Summer Sale Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: ecus65

C++ Institute CPA-21-02 - CPA - C++ Certified Associate Programmer

Page: 7 / 8
Total 257 questions

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

#include

using namespace std;

class First

{

public:

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

~First() { cout << "Destructor";}

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

};

int main()

{

First FirstObject;

FirstObject.Print();

}

A.

It prints: Constructorfrom First

B.

It prints: Constructorfrom FirstDestructor

C.

It prints: Constructorfrom FirstDestructorDestructor

D.

Compilation error at line 16

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:

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

};

class C:public B {

public:

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

};

int main()

{

A ob1;

B ob2;

C ob3;

B *obj;

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

A.

It prints: BB

B.

It prints: AA

C.

It prints: BC

D.

It prints: AB

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

#include

using namespace std;

void print(char *c);

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

{

print("Test");

return 0;

}

void print(char *c)

{

cout<

}

A.

It prints: Test

B.

It prints: T

C.

It prints: st

D.

None of these

What will be the output of the program?

#include

using namespace std;

int main()

{

int i=0;

for(; i<=5; i++)

cout << i;

return 0;

}

A.

012345

B.

0123

C.

5

D.

6

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

#include

#include

using namespace std;

class Base

{

string s;

public:

Base() { s="Sample text";}

Base(string s) { this?>s=s; }

void Print() { cout << s; }

};

int main()

{

Base *o = new Base();

o?>Print();

}

A.

It prints: Sample text

B.

It prints: Sample

C.

It prints: text

D.

None of these

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

#include

using namespace std;

int op(int x, int y);

float op(int x, float y);

int main()

{

int i=1, j=2, k;

float f=0.3;

k = op(i, j);

cout<< k << "," << op(0, f);

return 0;

}

int op(int x, int y)

{

return x+y;

}

float op(int x, float y)

{

return x?y;

}

A.

It prints: 3,1

B.

It prints: 3,?0.3

C.

It prints: 3,0

D.

It prints: 0,0

If there is one, point out an error in the program

#include

using namespace std;

int main()

{

int c = 'a';

switch(i)

{

case '2':

cout<<"OK";

case '1':

cout<<"Error";

default:

break;

}

return 0;

}

A.

No Error

B.

Use of undeclared identifier 'i'

C.

Illegal use of 'continue'

D.

Illegal use of 'break'

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

#include

using namespace std;

void fun(int*);

int main()

{

int *x;

int i=2;

x=&i;

fun(x);

cout<

return 0;

}

void fun(int *i)

{

*i = *i * *i;

}

A.

It prints: 2

B.

It prints: 4

C.

It prints: 0

D.

It prints: 1

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

#include

using namespace std;

#define A 1

int main()

{

#if A

cout<<"Hello";

#endif

cout<<"world";

return 0;

}

A.

It will print: Helloworld

B.

It will print: Hello

C.

It will print: world

D.

It will print: 0

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

#include

using namespace std;

int main()

{

union un

{

int x;

char c;

};

union un u1 = {10};

union un u2 = {'a'};

union un u3 = {20, 'a'};

cout<

cout<

cout<

return 0;

}

A.

It prints: 10aa

B.

It prints: 10a20a

C.

It prints: 1a

D.

Compilation error