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: 3 / 4
Total 257 questions

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

class A {

int x;

protected:

int y;

public:

int age;

};

class B : private A {

string name;

public:

void Print() {

cout << name << age;

}

};

A.

public

B.

private

C.

protected

D.

None of these

What happens if character 3 is entered as input?

#include

using namespace std;

class A {

public:

int i;

};

int main () {

int c;

A obj;

obj.i = 5;

cin >> c;

try

{

switch (c)

{

case A. throw 20;

case B. throw 5.2f;

case C. throw obj;

default: cout<<"No exception";

}

}

catch (int e)

{ cout << "int exception. Exception Nr. " << e; }

catch (A e)

{ cout << "object exception. Exception Nr. " << e.i; }

catch (...)

{ cout << "An exception occurred."; }

return 0;

}

A.

It prints: object exception. Exception Nr. 5

B.

It prints: int exception. Exception Nr.

C.

It prints: An exception occurred

D.

It prints: No exception

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

#include

using namespace std;

class A

{

public:

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

};

class B:public A

{

public:

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

};

int main()

{

A *obj;

A ob1;

obj = &ob1;

obj?>Print();

B ob2;

obj = &ob2;

obj?>Print();

}

A.

It prints: AB

B.

It prints: AA

C.

It prints: BA

D.

It prints: BB

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

#include

#include

using namespace std;

class complex{

double re, im;

public:

complex() : re(1),im(0.4) {}

complex operator+(complex &t);

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

};

complex complex::operator+ (complex &t){

complex temp;

temp.re = this?>re + t.re;

temp.im = this?>im + t.im;

return temp;

}

int main(){

complex c1,c2,c3;

c3 = c1 + c2;

c3.Print();

}

A.

It prints: 1 0.4

B.

It prints: 2 0.8

C.

It prints: 0 0

D.

Garbage value

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;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

A.

It prints: BBB

B.

It prints: AAA

C.

It prints: ABC

D.

It prints: ABB

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

#include

using namespace std;

int main(){

int i = 1;

if (--i==1) {

cout << i;

} else {

cout << i-1;

}

return 0;

}

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

It prints: 2

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;

}

A.

It prints: Test 4

B.

It prints: Test 3

C.

Compilation error

D.

It prints: Tes 3

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

#include

#include

using namespace std;

int mult(int f, int s, int t);

int main()

{

cout << mult(1,2,3);

return 0;

}

int mult(int f, int s, int t)

{

int mult_res;

mult_res = f*s*t;

return mult_res;

}

A.

It prints: 0

B.

It prints: 6

C.

It prints: 2

D.

It prints: 3

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

#include

using namespace std;

class A {

public:

//insert code here

};

class B:public A {

public:

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

};

class C:public B {

public:

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

};

int main()

{

A ob1;

B ob2;

C ob3;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

A.

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

B.

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

C.

virtual void Print(string s){ cout<

D.

None of these

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) { z = x + y; }

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;

b.Print();

return 0;

}

A.

It prints: 3

B.

It prints: 0

C.

It prints: 1

D.

It prints: 2

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

#include

using namespace std;

int main() {

float i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4 / 2;

cout << i;

return 0;

}

A.

It prints: 0

B.

It prints: 1

C.

It prints: 2

D.

It prints: 0.5

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

#include

using namespace std;

int x=5;

static int y=0;

void myFunction(int a)

{

y=++a;

}

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

{

int i=0;

myFunction(i);

cout<

}

A.

It prints: 0 5

B.

It prints: 5 1

C.

It prints: 1 5

D.

It prints: 5 0

What is the output of the program?

#include

#include

using namespace std;

struct Person {

int age;

};

class First

{

Person *person;

public:

First() {person = new Person;

person?>age = 20;

}

void Print(){

cout << person?>age;

}

};

int main()

{

First t[2];

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

t[i].Print();

}

A.

It prints: 10

B.

It prints: 2020

C.

It prints: 22

D.

It prints: 00

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

#include

#include

using namespace std;

class A {

public:

int x;

A() { x=0;}

};

class B {

public:

int x;

B() { x=1;}

};

class C :public A, public B {

public:

int x;

C(int x) {

this?>x = x;

A.

:x = x + 1;

}

void Print() { cout << x << A::x << B::x; }

};

int main () {

C c2(1);

c2.Print();

return 0;

}

B.

It prints: 1

C.

It prints: 121

D.

It prints: 111

E.

It prints: 2

What is the output of the program given below?

#include

using namespace std;

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

{

int i=10;

{

int i=0;

cout<

}

{

int i=5;

cout << i;

}

cout<

return 0;

}

A.

1010

B.

101010

C.

0510

D.

None of these

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

#include

#include

using namespace std;

class complex{

double re, im;

public:

complex() : re(1),im(0.4) {}

complex operator?(complex &t);

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

};

complex complex::operator? (complex &t){

complex temp;

temp.re = this?>re ? t.re;

temp.im = this?>im ? t.im;

return temp;

}

int main(){

complex c1,c2,c3;

c3 = c1 ? c2;

c3.Print();

}

A.

It prints: 1 0.4

B.

It prints: 2 0.8

C.

It prints: 0 0

D.

It prints: 1 0.8

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

#include

#include

using namespace std;

class A {

public:

int x;

};

class B : public A {

public:

B() { x=1;}

B(int x) {this?>x = x;}

};

int main () {

B c1;

B c2(10);

cout << c1.x;

cout << c2.x;

return 0;

}

A.

It prints: 010

B.

It prints: 110

C.

It prints: 00

D.

It prints: 1

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

default:

cout<<"No exception";

}

}

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;

}

A.

It prints: float exception. Exception Nr.

B.

It prints: int exception. Exception Nr.

C.

It prints: An exception occurred

D.

It prints: No exception

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(1,2);

c1.print();

return 0;

}

A.

It prints: 1 0

B.

It prints: 1 1

C.

It prints: 1 2

D.

Compilation error

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(1) & fun(0);

cout << i;

return 0;

}

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

Compilation error

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