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

What is the output of the program?

#include

#include

using namespace std;

class First

{

string name;

public:

First() {

name = "Alan";

}

void Print(){

cout << name;

}

};

int main()

{

First ob1,*ob2;

ob2 = new First();

ob1.Print();

ob2?>Print();

}

A.

Garbage value

B.

It prints: AlanAlan

C.

It prints: Alan

D.

It prints: Al

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<

}

cout<

return 0;

}

A.

1010

B.

100

C.

010

D.

None of these

What is the output of the program?

#include

#include

using namespace std;

int main()

{

string s1[]= {"Hello" , "World" };

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

cout << s1[i];

}

return( 0 );

}

A.

It prints: HelloWorld

B.

It prints: Hello

C.

It prints: WorldHello

D.

It prints: World

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;

int z;

A() { x=2; y=2; z=3; }

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

void Print() {

cout << z;

}

};

int main () {

A a(2,5);

a.Print();

return 0;

}

A.

It prints: ?3

B.

It prints: 2

C.

It prints: 6

D.

It prints: 5

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

#include

#include

using namespace std;

class A {

public:

string s;

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

};

class B {

public:

string s;

B (A a) { this?>s = a.s; }

void print() { cout<

};

int main()

{

A a("Hello world");

B b=a;

b.print();

}

A.

It prints: Hello world

B.

It prints: Hello

C.

Compilation error

D.

None of these

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

#include

#include

using namespace std;

class myClass : public exception

{

virtual const char* what() const throw()

{

return "My exception.";

}

} obj;

int main () {

try

{

throw obj;

}

catch (exception& e)

{

cout << e.what() << endl;

}

return 0;

}

A.

It prints: My exception.

B.

It prints: 0

C.

It prints: 1

D.

Compilation error

What is the output of the program if characters 't', 'e', 's' and 't' enter are supplied as input?

#include

#include

using namespace std;

int main()

{

string s;

getline( cin, s );

cout << s << " " << s.length();

return( 0 );

}

A.

It prints: test 4

B.

It prints: test

C.

It prints: test 5

D.

It prints: 4

Which of the following is a logical operator?

A.

&

B.

&&

C.

||

D.

!

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;

}

};

A.

public

B.

private

C.

protected

D.

None of these

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

A *bc = (A*)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

Which of the following statements are correct about an array?

int tab[10];

A.

The array can store 10 elements.

B.

The expression tab[1] designates the very first element in the array.

C.

The expression tab[9] designates the last element in the array.

D.

It is necessary to initialize the array at the time of declaration.

Which of the structures is incorrect?

1:

struct s1{

int x;

long int li;

};

2:

struct s2{

float f;

struct s2 *s;

};

3:

struct s3{

float f;

struct s3 s;

};

A.

1

B.

2

C.

3

D.

2, 3

Given:

#include

#include

using namespace std;

int main () {

try

{

int * myarray= new int[1000];

}

catch (bad_alloc&)

{

cout << "Error allocating memory";

}

catch (exception& e)

{

cout << "Standard exception";

}

catch (...)

{

cout << "Unknown exception";

}

return 0;

}

What will happen if we use the operator “new” and the memory cannot be allocated?

A.

It prints: Error allocating memory

B.

It prints: Standard exception

C.

It prints: Unknown exception

D.

Compilation error

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

#include

#include

using namespace std;

const int size = 3;

class A {

public:

string name;

A() { name = "Bob";}

A(string s) { name = s;}

A(A &a) { name = a.name;}

};

class B : public A {

public:

B() { }

B(string s) : A(s) { }

void Print() {

cout << name;

}

};

int main () {

B b1("Alan");

b1.Print();

return 0;

}

A.

It prints: 111Alan

B.

It prints: Bob

C.

It prints: Alan

D.

It prints: 0

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

#include

using namespace std;

int main()

{

const int x=20;

const int *ptr;

ptr = &x;

*ptr = 10;

cout<<*ptr;

return 0;

}

A.

It prints: 20

B.

It prints: 10

C.

Compilation error at line 8

D.

It prints address of ptr

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

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

};

int main () {

A a2("Test");

B b1(10);

B b2(b1);

return 0;

}

A.

It prints: A no parametersA no parametersB string parameter

B.

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

C.

It prints: A no parametersB string parameter

D.

It prints: A no parametersA no parameters

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

{

First FirstObject;

FirstObject.Print();

Second SecondObject;

SecondObject.Print();

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Firstfrom Second

D.

It prints: from Secondfrom Second

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