Weekend Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: xmas50

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

Page: 2 / 8
Total 257 questions

What is the output of the program if character 4 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';

default:

cout<<"No exception";

}

}

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;

}

A.

It prints: float exception. Exception Nr.

B.

It prints: int exception. Exception Nr.

C.

It prints: An exception occurred

D.

It prints: No exception

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

#include

using namespace std;

void fun(int);

int main()

{

int a=0;

fun(a);

return 0;

}

void fun(int n)

{

if(n < 2)

{

fun(++n);

cout << n;

}

}

A.

It prints: 21

B.

It prints: 012

C.

It prints: 0

D.

None of these

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

#include

using namespace std;

class BaseC

{

int *ptr;

public:

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

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

~BaseC() { delete ptr; }

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

};

int main()

{

BaseC *o = new BaseC(5);

o?>Print();

}

A.

It prints: 5

B.

It prints: 10

C.

It prints: 1

D.

It prints: 0

Which code, inserted at line 5, generates the output "ABC"?

#include

using namespace std;

class A {

public:

//insert code here

};

class B:public A {

public:

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

};

class C:public B {

public:

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

};

int main()

{

A ob1;

B ob2;

C ob3;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

A.

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

B.

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

C.

virtual void Print(string s){ cout<

D.

None of these

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";}

};

int main()

{

A *obj;

A ob1;

obj = &ob1;

obj?>Print();

B ob2;

obj = &ob2;

obj?>Print();

}

A.

It prints: AB

B.

It prints: AA

C.

It prints: BA

D.

It prints: BB

Point out an error in the program.

#include

using namespace std;

int main()

{

char s1[] = "Hello";

char s2[] = "world";

char *const ptr = s1;

*ptr = 'a';

ptr = s2;

return 0;

}

A.

No error

B.

Cannot modify a const object

C.

Compilation error at line 9

D.

None of these

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

#include

using namespace std;

#include

using namespace std;

class First

{

public:

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

};

int main()

{

First t[2];

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

t[i].Print();

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

Compilation error

D.

Runtime error.

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

#include

using namespace std;

int getValue();

int main()

{

const int x = getValue();

cout<

return 0;

}

int getValue()

{

return 5;

}

A.

It will print 0

B.

The code will not compile.

C.

It will print 5

D.

It will print garbage value

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

#include

using namespace std;

int main()

{

int x=2, *y;

y = &x;

cout << *y + x;

return 0;

}

A.

It prints: 1

B.

It prints: 2

C.

It prints: 4

D.

It prints: 0

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;

}

A.

It prints: 20

B.

It prints: 0

C.

It prints address of ptr

D.

It prints: 2