Weekend Special 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: save70

Free and Premium C++ Institute CPA Dumps Questions Answers

Page: 1 / 8
Total 220 questions

C++ Certified Associate Programmer Questions and Answers

Question 1

What happens when you attempt to compile and run the following code?

#include

using namespace std;

#define DEF_A 0

int main(int argc, char *argv[]) {

cout << DEF_A;

return 0;

}

Options:

A.

It prints: 1

B.

It prints: 0

C.

It prints: ?1

D.

Compilation error

Buy Now
Question 2

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class A

{

public:

void Print(){ cout<<"A";}

};

class B:public A

{

public:

void Print(){ cout<< "B";}

};

int main()

{

A *obj;

A ob1;

obj = &ob1;

obj?>Print();

B ob2;

obj = &ob2;

obj?>Print();

}

Options:

A.

It prints: AB

B.

It prints: AA

C.

It prints: BA

D.

It prints: BB

Question 3

What is the output of the program?

#include

#include

using namespace std;

int main()

{

string s1[]= {"Hello" , "World" };

for (int i=0; i<2; i++) {

cout << s1[i];

}

return( 0 );

}

Options:

A.

It prints: HelloWorld

B.

It prints: Hello

C.

It prints: WorldHello

D.

It prints: World

Question 4

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int main()

{

int i=2;

switch(i)

{

case 1:

cout<<"Hello";

case 2:

cout<<"world";

case 3:

cout<<"End";

} return 0;

}

Options:

A.

It prints: Hello

B.

It prints: world

C.

It prints: worldEnd

D.

It prints: End

Question 5

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int main()

{

int x=20;

int *ptr;

ptr = &x;

cout<<*ptr;

return 0;

}

Options:

A.

It prints: 20

B.

It prints: 0

C.

It prints address of ptr

D.

It prints: 2

Question 6

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class B;

class A {

int age;

public:

A () { age=5; };

friend class B;

};

class B {

string name;

public:

B () { name="Bob"; };

void Print(A ob) {

cout << name << ob.age;

}

};

int main () {

A a;

B b;

b.Print(a);

return 0;

}

Options:

A.

It prints: Bob5

B.

It prints: Bob

C.

It prints: 5

D.

None of these

Question 7

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

inline float sum(float a,float b)

{

return a+b;

}

int main()

{

float a,b;

a = 1.5; b = 3.4;

cout<<sum(a,b);

return 0;

}

Options:

A.

It prints: 0

B.

It prints: 4.9

C.

It prints: 5

D.

It prints: 4

Question 8

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class A {

public:

int x;

A() { x=0;}

A(int x) { this?>x=x;}

};

class B : private A {

public:

using A::x;

B() { x=1;}

B(int x) {this?>x = x;}

};

int main () {

B c1;

B c2(?5);

cout << c1.x;

cout << c2.x;

return 0;

}

Options:

A.

It prints: 5

B.

It prints: 1?5

C.

It prints: 05

D.

It prints: 0

Question 9

Which code, inserted at line 14, generates the output "3.14 10"?

#include

using namespace std;

namespace myNamespace1

{

int x = 5;

int y = 10;

}

namespace myNamespace2

{

float x = 3.14;

float y = 1.5;

}

int main () {

//insert code here

cout << x << " " << y;

return 0;

}

Options:

A.

using myNamespace2::y; using myNamespace1::x;

B.

using namespace myNamespace1;

C.

using namespace myNamespace1; using namespace myNamespace2;

D.

using myNamespace1::y; using myNamespace2::x;

Question 10

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

A() { x=1; y=2; z=3; }

};

class B : public A {

string z;

public:

void set() {

y = 4;

z = "John";

}

void Print() {

cout << y << z;

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Options:

A.

It prints: 4John

B.

It prints: 2John

C.

It prints: 23

D.

It prints: 43

Question 11

Which code, inserted at line 10, generates the output "Hello World"?

#include

#include

using namespace std;

string fun(string, string);

int main()

{

string s="Hello";

string *ps;

ps = &s;

//insert code here

return 0;

}

string fun(string s1, string s2)

{

return s1+s2;

}

Options:

A.

cout << fun(" World");

B.

cout << fun(*ps);

C.

cout << fun("Hello");

D.

cout << fun("Hello", " World");

Question 12

What will the variable "age" be in class B?

class A {

int x;

protected:

int y;

public:

int age;

};

class B : private A {

string name;

public:

void Print() {

cout << name << age;

}

};

Options:

A.

public

B.

private

C.

protected

D.

None of these

Question 13

Which code, inserted at line 8, generates the output "0102020"?

#include

using namespace std;

class Base {

static int age;

public:

Base () {};

~Base () {};

//insert code here

void Print() { cout << age;}

};

int Base::age=0;

int main () {

Base a,*b;

b = new Base();

a.Print();

a.setAge(10);

a.Print();

b?>setAge();

a.Print();

b?>Print();

return 0;

}

Options:

A.

void setAge(int a) {age = a;}

B.

void setAge() {age = 20;}

C.

void setAge() {age = 10;}

D.

void setAge(int a=20) {age = a;}

Question 14

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class A {

public:

A() { cout << "A no parameters";}

A(string s) { cout << "A string parameter";}

A(A &a) { cout << "A object A parameter";}

};

class B : public A {

public:

B() { cout << "B no parameters";}

B(string s) { cout << "B string parameter";}

};

int main () {

A a2("Test");

B b1("Alan");

B b2(b1);

return 0;

}

Options:

A.

It prints: A no parametersA no parametersB string parameter

B.

It prints: A string parameterA no parametersB string parameterA object A parameter

C.

It prints: A no parametersB string parameter

D.

It prints: A no parametersA no parameters

Question 15

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class BaseClass

{

public:

int *ptr;

BaseClass(int i) { ptr = new int(i); }

~BaseClass() { delete ptr; delete ptr;}

void Print() { cout << *ptr; }

};

void fun(BaseClass x);

int main()

{

BaseClass o(10);

fun(o);

o.Print();

}

void fun(BaseClass x) {

cout << "Hello:";

}

Options:

A.

It prints: Hello:1

B.

It prints: Hello:

C.

It prints: 10

D.

Runtime error.

Question 16

Which of the structures is incorrect?

1:

struct s1{

int x;

long int li;

};

2:

struct s2{

float f;

struct s2 *s;

};

3:

struct s3{

float f;

struct s3 s;

};

Options:

A.

1

B.

2

C.

3

D.

2, 3

Question 17

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int main(){

int i = 1;

if (--i==1) {

cout << i;

} else {

cout << i-1;

}

return 0;

}

Options:

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

It prints: 2

Question 18

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class First

{

public:

void Print(){ cout<<"from First";}

};

class Second:public First

{

public:

void Print(){ cout<< "from Second";}

};

void fun(First *obj);

int main()

{

First FirstObject;

fun(&FirstObject);

Second SecondObject;

fun(&SecondObject);

}

void fun(First *obj)

{

obj?>Print();

}

Options:

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Firstfrom Second

D.

It prints: from Secondfrom Second

Question 19

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int mul (int a, int b=2)

{

int r;

r=a*b;

return (r);

}

int main ()

{

cout << mul(1) << mul(2,4);

return 0;

}

Options:

A.

It prints: 2

B.

It prints: 28

C.

It prints: 8

D.

It prints: 6

Question 20

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

int f(int i);

int main()

{

int i=0;

i++;

for (i=0; i<=2; i++)

{

cout<<f(i);

}

return 0;

}

int f(int a)

{

return a+a;

}

Options:

A.

It prints: 202020

B.

It prints: 012

C.

It prints: 024

D.

It prints: 0

Question 21

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class BaseC

{

public:

int *ptr;

BaseC() { ptr = new int(10);}

BaseC(int i) { ptr = new int(i); }

~BaseC() { delete ptr; }

};

void fun(BaseC x);

int main()

{

BaseC *o = new BaseC(5);

fun(*o);

}

void fun(BaseC x) {

cout << "Hello:"<<*x.ptr;

}

Options:

A.

It prints: Hello:50

B.

It prints: Hello:10

C.

It prints: Hello:5

D.

Compilation error

Question 22

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

struct Person {

string name;

int age;

};

class First

{

Person *person;

public:

First() {person = new Person;

person?>name = "John";

person?>age = 30;

}

void Print(){

cout<<person?>name << " "<< person?>age;

}

};

int main()

{

First t;

t.Print();

}

Options:

A.

It prints: 30

B.

It prints: John

C.

It prints: John 30

D.

It prints: John 30John 30

Question 23

Which code, inserted at line 10, generate the output "50"?

#include

using namespace std;

class Base {

int age;

public:

Base () {

age=5;

};

//insert code here

void Print() { cout << age;}

};

void setAge(Base &ob) {ob.age = 0;}

int main () {

Base a;

a.Print();

setAge(a);

a.Print();

return 0;

}

Options:

A.

friend void setAge(Base ob);

B.

friend void setAge(Base *ob);

C.

friend void setAge(Base &ob);

D.

None of these

Question 24

What is the output of the program if character 3 is supplied as input?

#include

using namespace std;

int main () {

int c;

cin >> c;

try

{

switch (c)

{

case 1:

throw 20;

case 2:

throw 5.2f;

case 3:

throw 'a';

}

}

catch (int e)

{ cout << "int exception. Exception Nr. " << e; }

catch (float e)

{ cout << "float exception. Exception Nr. " << e; }

catch (...)

{ cout << "An exception occurred."; }

return 0;

}

Options:

A.

It prints: float exception. Exception Nr.

B.

It prints: int exception. Exception Nr.

C.

It prints: An exception occurred.

D.

It prints: float exception. Exception Nr.

Question 25

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int op(int x, int y)

{

int i;

i = x + y;

return i;

}

int main()

{

int i=1, j=2, k, l;

k = op(i, j);

l = op(j, i);

cout<< k << "," << l;

return 0;

}

Options:

A.

It prints: 1,2

B.

It prints: ?1,1

C.

It prints: 1,1

D.

It prints: 3,3

Question 26

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class First

{

public:

virtual void Print(){ cout<<"from First";}

};

class Second:public First

{

public:

void Print(){ cout<< "from Second";}

};

void fun(First *obj);

int main()

{

First FirstObject;

fun(&FirstObject);

Second SecondObject;

fun(&SecondObject);

}

void fun(First *obj)

{

obj?>Print();

}

Options:

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Firstfrom Second

D.

It prints: from Secondfrom Second

Question 27

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int min(int a, int b);

int main()

{

int b=10;

b = min(5,20);

cout << b;

return 0;

}

int min(int a, int b)

{

if (a

return(a);

else

return(b);

}

Options:

A.

It prints: 10

B.

It prints: 20

C.

It prints: 5

D.

It prints: 0

Question 28

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class First

{

public:

First() { cout << "Constructor";}

void Print(){ cout<<"from First";}

};

int main()

{

First FirstObject;

FirstObject.Print();

}

Options:

A.

It prints: Constructorfrom First

B.

It prints: Constructor

C.

It prints: from First

D.

None of these

Question 29

What will the variable "y" be in class B?

class A {

int x;

protected:

int y;

public:

int age;

};

class B : protected A {

string name;

public:

void Print() {

cout << name << age;

}

};

Options:

A.

public

B.

private

C.

protected

D.

None of these

Question 30

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class A {

public :

void print() {

cout << "A ";

}

};

class B {

public :

void print() {

cout << "B ";

}

};

int main() {

B sc[2];

B *bc = (B*)sc;

for (int i=0; i<2;i++)

(bc++)->print();

return 0;

}

Options:

A.

It prints: A A

B.

It prints: B B

C.

It prints: A B

D.

It prints: B A

Question 31

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int main()

{

long int x,y=10;

double d;

d = 3.99;

x=(int) d;

cout << x <<", ";

d=float (y);

cout << d;

return 0;

}

Options:

A.

It prints: 3, 10

B.

It prints: 3.99, 10

C.

It prints: 4, 10.0

D.

It prints: 4, 10

Question 32

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

A() { x=1; y=2; z=3; }

};

class B : public A {

string z;

public:

void set() { y = 4; z = "John"; }

void Print() { cout << y << A::z; }

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Options:

A.

It prints: 4John

B.

It prints: 2John

C.

It prints: 23

D.

It prints: 43

Question 33

What happens if you try to compile and run this program?

#include

using namespace std;

int main (int argc, const char * argv[])

{

print("Test");

return 0;

}

void print(int c[])

{

cout<<c;

}

Options:

A.

It prints: Test

B.

Compilation fails

C.

Program terminates abnormally

D.

None of these

Page: 1 / 8
Total 220 questions