CPA C++ Certified Associate Programmer

Loading demo links...

Showing 10–12 of 15 questions

Question 10 (Volume A)

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

#include

#include

using namespace std;

class myClass : public exception

{

virtual const char* what() const throw()

{

return "My exception.";

}

} obj;

int main () {

try

{

throw obj;

}

catch (exception& e)

{

cout << e.what() << endl;

}

return 0;

}

Select an option, then click Submit answer.

  • It prints: My exception.

  • It prints: 0

  • It prints: 1

  • Compilation error

Question 11 (Volume A)

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

}

}

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;

}

Select an option, then click Submit answer.

  • It prints: float exception. Exception Nr.

  • It prints: int exception. Exception Nr. 20

  • It prints: An exception occurred

  • It prints: float exception. Exception Nr. 5.2

Question 12 (Volume A)

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

#include

using namespace std;

void fun(char*);

int main()

{

char t[4]={'0', '1', '2', '3'};

fun(&t[2]);

return 0;

}

void fun(char *a)

{

cout << *a;

}

Select an option, then click Submit answer.

  • It prints: 2

  • It prints: 21

  • It prints: 00

  • It prints: 02