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

Page: 1 / 14
Total 257 questions
Question 1

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;

}



Answer : A


Question 2

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 min(int,int);

int b;

b = min(10,20);

cout << b;

return 0;

}

int min(int a, int b)

{

return(b);

}



Answer : A


Question 3

Which code, inserted at line 18, generates the output "AB"

#include

using namespace std;

class A

{

public:

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

void Print2(){ cout<< "a";}

};

class B:public A

{

public:

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

void Print2(){ cout<< "b";}

};

int main()

{

B ob2;

//insert code here

ob2.Print();

}



Answer : D


Question 4

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;

}



Answer : C


Question 5

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

#include

using namespace std;

int main()

{

int x=0;

int *ptr;

ptr = &x;

cout<

return 0;

}



Answer : A


Question 6

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

#include

using namespace std;

int main()

{

float x=3.5,y=1.6;

int i,j=2;

i = x + j + y;

cout << i;

return 0;

}



Answer : A


Question 7

Which statement should be added in the following program to make work it correctly?

using namespace std;

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

{

cout<<"Hello";

}



Answer : C


Page:    1 / 14   
Total 257 questions