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

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

#include

#include

using namespace std;

class Base

{

string s;

public:

Base() { s="Sample text";}

Base(string s) { this?>s=s; }

void Print() { cout << s; }

};

int main()

{

Base *o = new Base();

o?>Print();

}

A.

It prints: Sample text

B.

It prints: Sample

C.

It prints: text

D.

None of these

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

A.

It prints: 5.2110.0

B.

It prints: 5.210.0

C.

It prints: 52.10

D.

It prints: 5210

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

A.

a = b * c;

B.

return a = b * c;

C.

return a = b * *c;

D.

a = b * *c;

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

A.

It prints: 33

B.

It prints: 007

C.

It causes a compilation error

D.

lit prints: 9

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;

}

A.

It prints: 123

B.

It prints: 23

C.

It prints: 3

D.

It prints: 2

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

A.

It prints: 1

B.

It causes a compilation error

C.

It prints: -1

D.

It prints: 0

If a function, which is not a method, needs to save any value between its subsequent invocations, this can be done by: (Choose two.)

A.

setting a variable declared inside the function with the static modifier

B.

setting a parameter of the function

C.

setting a variable declared outside the function

D.

setting a variable declared inside the function without the static modifier

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

#include

#include

using namespace std;

void fun(int i);

int main()

{

int i=0;

i++;

for (i=0; i<=5; i++)

{

fun(i);

}

return 0;

}

void fun(int i)

{

if (i==3)

return;

cout << i;

}

A.

It prints: 05

B.

It prints: 012345

C.

It prints: 01245

D.

It prints: 0

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

#include

using namespace std;

int main()

{

union un

{

int x;

char c;

};

union un u1 = {10};

union un u2 = {'a'};

union un u3 = {20, 'a'};

cout<

cout<

cout<

return 0;

}

A.

It prints: 10aa

B.

It prints: 10a20a

C.

It prints: 1a

D.

Compilation error

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

#include

#include

using namespace std;

class A {

public:

int age;

A () { age=5; };

};

class B : private A {

string name;

public:

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

void Print() {

cout << name << age;

}

};

int main () {

B b,*ob;

ob = &b;

ob?>age = 10;

ob?>Print();

return 0;

}

A.

It prints: Bob55

B.

It prints: Bob1

C.

It prints: 10

D.

Compilation error

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 b=10;

b = min(5,20);

cout << b;

return 0;

}

int min(int a, int b)

{

if (a

return(a);

else

return(b);

}

A.

It prints: 10

B.

It prints: 20

C.

It prints: 5

D.

It prints: 0

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(2), y(2), z(1) { 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: 4

B.

It prints: 0

C.

It prints: 3

D.

It prints: 2

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

#include

#include

using namespace std;

string fun(string, string);

int main()

{

string s="Hello";

cout << fun(s, " World");

return 0;

}

string fun(string s1, string s2)

{

return s1+s2;

}

A.

It will print: Hello World

B.

It will print: Hello

C.

It will print: World

D.

It will print: HW

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

A.

ob2.A::print();

B.

ob2 –> A::print();

C.

ob2.B::print();

D.

ob2 –> B::print();

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

}

A.

It prints: 20

B.

It prints: 10

C.

It prints: 1020

D.

It prints: 2010

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

#include

using namespace std;

class BaseC

{

public:

int *ptr;

BaseC() { ptr = new int(10);}

BaseC(int i) { ptr = new int(i); }

~BaseC() { delete ptr; }

};

void fun(BaseC x);

int main()

{

BaseC *o = new BaseC(5);

fun(*o);

}

void fun(BaseC x) {

cout << "Hello:"<<*x.ptr;

}

A.

It prints: Hello:50

B.

It prints: Hello:10

C.

It prints: Hello:5

D.

Compilation error

What is not inherited from the base class?

A.

constructor

B.

destructor

C.

operator=()

D.

operator+()

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

#include

using namespace std;

class Base {

int age;

public:

class C {

int b;

void PrintC() { cout << b; }

};

Base () {age=5;};

void setAge(int a=20) {age = a;}

void Print() { cout << age;}

};

int main () {

Base a;

a.setAge(10);

a.Print();

return 0;

}

A.

It prints: 1020

B.

It prints: 105

C.

It prints: 10

D.

It prints: 20

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

#include

#include

using namespace std;

class Second;

class Base {

int age;

public:

Base () { age=5; };

friend void set(Base &ob, Second &so);

void Print() { cout << age;}

};

class Second {

string name;

public:

friend void set(Base &ob, Second &so);

void Print() { cout << name;}

};

void set(Base &ob, Second &so) {

ob.age = 0; so.name = "Bill";

}

int main () {

Base a;

Second b;

set(a,b);

a.Print();

b.Print();

return 0;

}

A.

It prints: 0Bill

B.

Compilation error

C.

It prints: Bill0

D.

None of these

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

#include

#include

using namespace std;

class A {

public:

A() { cout << "A no parameters";}

A(string s) { cout << "A string parameter";}

A(A &a) { cout << "A object A parameter";}

};

class B : public A {

public:

B() { cout << "B no parameters";}

B(string s) { cout << "B string parameter";}

};

int main () {

A a2("Test");

B b1("Alan");

B b2(b1);

return 0;

}

A.

It prints: A no parametersA no parametersB string parameter

B.

It prints: A string parameterA no parametersB string parameterA object A parameter

C.

It prints: A no parametersB string parameter

D.

It prints: A no parametersA no parameters

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