Limited-Time Offer: Enjoy 50% Savings! Ends in 00h 00m 00s Coupon code: 50OFF
Skip to content

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

Page: 1 / 18 Total 257 questions

Want more questions? Get Premium Access.

Question 1

What is the output of the program?

#include

#include

using namespace std;

int main()

{

string s1="Wo";

string s2;

s2 = s1;

string s3;

s3 = s2.append("rldHello");

cout << s3;

return( 0 );

}

Correct Answer: A. It prints: WorldHello

Question 2

What is the meaning of the following declaration? (Choose two.)

char **ptr;

Correct Answer: A. ptr is a pointer to a pointer to char; B. ptr is a pointer to char*

Question 3

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

#include

using namespace std;

int fun(int x) {

return 2*x;

}

int main(){

int i;

i = fun(0.5) || fun(0);

cout << i;

return 0;

}

Correct Answer: A. It prints: 0

Question 4

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

#include

using namespace std;

int op(int x, int y);

int main()

{

int i=2, j=2, k;

float f=0.3;

k = op(i, j);

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

return 0;

}

int op(int x, int y)

{

return x+y;

}

Correct Answer: A. It prints: 4,1

Question 5

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

#include

using namespace std;

int main()

{

int *t;

t = new int[2];

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

t[i]=0;

}

cout << t[1];

}

Correct Answer: A. It prints: 0

Question 6

Which code, inserted at line 14, generates the output "3.14 10"?

#include

using namespace std;

namespace myNamespace1

{

int x = 5;

int y = 10;

}

namespace myNamespace2

{

float x = 3.14;

float y = 1.5;

}

int main () {

//insert code here

cout << x << " " << y;

return 0;

}

Correct Answer: D. using myNamespace1::y; using myNamespace2::x;

Question 7

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

#include

#include

#include

using namespace std;

int main(void)

{

string s;

s = "Test";

s.resize (s.size() ? 1);

cout<

return 0;

}

Correct Answer: D. It prints: Tes 3

Question 8

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

Correct Answer: C. It causes a compilation error

Question 9

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

#include

using namespace std;

namespace myNamespace1

{

int var = 5;

}

namespace myNamespace2

{

char var = 'b';

}

int main () {

//insert code here

return 0;

}

Correct Answer: C. cout << myNamespace1::var << myNamespace2::var;

Question 10

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

#include

using namespace std;

int main(){

int i, j;

for(i = 0, j = 1; j < 2, i < 4; i++, j++);

cout << i << " " << j;

return 0;

}

Correct Answer: A. It prints: 4 5

Question 11

What is the expected result of the following program?

Correct Answer: C. It prints: 42

Question 12

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();

}

Correct Answer: A. It prints: 5

Question 13

Which of the following operations is INCORRECT?

Correct Answer: C. float f=12,2;

Question 14

What will the variable "age" be in class B?

class A {

int x;

protected:

int y;

public:

int age;

A () { age=5; };

};

class B : public A {

string name;

public:

B () { name="Bob"; };

void Print() {

cout << name << age;

}

};

Correct Answer: A. public

Question 15

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

#include

using namespace std;

int op(int x, int y)

{

int i;

i = x + y;

return i;

}

int main()

{

int i=1, j=2, k, l;

k = op(i, j);

l = op(j, i);

cout<< k << "," << l;

return 0;

}

Correct Answer: D. It prints: 3,3