C++ Institute CPA-21-02 CPA - C++ Certified Associate Programmer Exam Practice Test

Page: 1 / 14
Total 257 questions
Question 1

What is the expected output of the following program?



Answer : B


Question 2

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

#include

using namespace std;

int fun(int);

int main()

{

int *x = new int;

*x=10;

//insert code here

return 0;

}

int fun(int i)

{

return i*i;

}



Answer : A, B


Question 3

Which definitions are correct?



Answer : A, C


Question 4

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

#include

using namespace std;

int main()

{

int a=5;

cout << ((a < 5) ? 9.9 : 9);

}



Answer : A


Question 5

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 6

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

#include

#include

using namespace std;

class A {

protected:

int y;

public:

int x, z;

A() : x(1), y(2), z(0) {}

A(int a, int b) : x(a), y(b) { z = x * y;}

void Print() { cout << z; }

};

class B : public A {

public:

int y;

B() : A() {}

B(int a, int b) : A(a,b) {}

void Print() { cout << z; }

};

int main () {

A b(2,5);

b.Print();

return 0;

}



Answer : A


Question 7

What is the output of the program?

#include

using namespace std;

#define PRINT(i) cout<

int main()

{

int y=2, z=3;

PRINT(y);

PRINT(z);

return 0;

}



Answer : B


Page:    1 / 14   
Total 257 questions