Summer Sale Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: s2p65

Easiest Solution 2 Pass Your Certification Exams

CPA-21-02 C++ Institute CPA - C++ Certified Associate Programmer Free Practice Exam Questions (2025 Updated)

Prepare effectively for your C++ Institute CPA-21-02 CPA - C++ Certified Associate Programmer certification with our extensive collection of free, high-quality practice questions. Each question is designed to mirror the actual exam format and objectives, complete with comprehensive answers and detailed explanations. Our materials are regularly updated for 2025, ensuring you have the most current resources to build confidence and succeed on your first attempt.

Page: 1 / 4
Total 257 questions

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

#include

using namespace std;

#define A 1

int main()

{

#if A

cout<<"Hello";

#endif

cout<<"world";

return 0;

}

A.

It will print: Helloworld

B.

It will print: Hello

C.

It will print: world

D.

It will print: 0

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

A.

It prints: T

B.

It prints an empty line

C.

It prints: Tesc

D.

It prints: st

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 :

void print() {

cout << "B ";

}

};

int main() {

B sc[2];

B *bc = (B*)sc;

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

(bc++)->print();

return 0;

}

A.

It prints: A A

B.

It prints: B B

C.

It prints: A B

D.

It prints: B A

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

#include

using namespace std;

class First

{

public:

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

};

class Second

{

public:

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

};

int main()

{

Second t[2];

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

t[i].Print();

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Secondfrom Second

D.

It prints: from Second

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

#include

using namespace std;

class complex{

double re;

double im;

public:

complex() : re(0),im(0) {}

complex(double x) { re=x,im=x;};

complex(double x,double y) { re=x,im=y;}

void print() { cout << re << " " << im;}

};

int main(){

complex c1;

c1.print();

return 0;

}

A.

It prints: 1 0

B.

It prints: 1 1

C.

It prints: 0 0

D.

Compilation error

Which of the following operators accept integer arguments only? (Choose two.)

A.

|

B.

| |

C.

~

D.

!

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;

}

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

Compilation error

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

#include

using namespace std;

void print(char *c);

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

{

print("Test");

return 0;

}

void print(char *c)

{

cout<

}

A.

It prints: Test

B.

It prints: T

C.

It prints: st

D.

None of these

Which of the following is a correct way to define the function fun() in the program below?

#include

#include

#include

using namespace std;

int main()

{

int a[2][2];

fun(a);

return 0;

}

A.

void fun(int *p[2]) {}

B.

void fun(int *p[2][2]) {}

C.

void fun(int *p[][2]) {}

D.

void fun(int p[][2]) {}

The following declaration:

int i = 0b10;

A.

is invalid

B.

sets variable i with an integer value equal to 10

C.

sets variable i with an integer value equal to 2 (10 binary)

D.

sets variable i with an integer value equal to 8 (10 octal)

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

#include

using namespace std;

int main()

{

int i = 5;

do {

i??;

cout<

}

while(i >= 0);

return 0;

}

A.

It prints: 43210?1

B.

It prints: ?1

C.

It prints: 4321

D.

It prints: 1

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

#include

using namespace std;

int main() {

int i, j;

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

for(j = i; j < i + 1; j++)

if(j == i)

continue;

else

break;

}

cout << j;

return 0;

}

A.

It prints: 0

B.

It prints: 3

C.

It prints: 2

D.

It prints: 1

Which code line inserted instead of the comment below will cause the program to produce the expected output?

A.

using namespace myNamespace1; using namespace myNamespace2;

B.

using namespace myNamespace1;

C.

using namespace myNamespace1::y; using myNamespace2::x;

D.

using namespace myNamespace2::y; using myNamespace1::x;

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

#include

using namespace std;

int main()

{

int i = 4;

while(i >= 0) {

cout<

i??;

}

return 0;

}

A.

It prints:”43210”

B.

It prints:”3210”

C.

It prints: ”3210?1”

D.

None of these

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

#include

using namespace std;

void fun(int*);

int main()

{

int *x;

int i=2;

x=&i;

fun(x);

cout<

return 0;

}

void fun(int *i)

{

*i = *i * *i;

}

A.

It prints: 2

B.

It prints: 4

C.

It prints: 0

D.

It prints: 1

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

};

class C:public B {

public:

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

};

int main()

{

A ob1;

B ob2;

C ob3;

B *obj;

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

A.

It prints: BB

B.

It prints: AA

C.

It prints: BC

D.

It prints: AB

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

#include

using namespace std;

int main()

{

int i = 0;

do {

i++;

if (i==3)

break;

cout<

}

while(i < 5);

return 0;

}

A.

It prints: 12

B.

It prints: 1

C.

It prints: 0

D.

No output

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

#include

using namespace std;

int op(int x, int y);

float op(int x, float y);

int main()

{

int i=1, j=2, k;

float f=0.3;

k = op(i, j);

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

return 0;

}

int op(int x, int y)

{

return x+y;

}

float op(int x, float y)

{

return x?y;

}

A.

It prints: 3,1

B.

It prints: 3,?0.3

C.

It prints: 3,0

D.

It prints: 0,0

What is the output of the program given below?

#include

using namespace std;

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

{

float f=?10.501;

cout<<(int)f;

}

A.

0

B.

11

C.

?10

D.

?11

What is the output of the program given below?

#include

using namespace std;

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

{

enum state { ok, error, warning};

enum state s1, s2, s3, s4;

s1 = ok;

s2 = warning;

s3 = error;

s4 = ok;

cout << s1<< s2<< s3<< s4;

return 0;

}

A.

1234

B.

compilation fails

C.

0210

D.

1322

Page: 1 / 4
Total 257 questions
Copyright © 2014-2025 Solution2Pass. All Rights Reserved