Exam2pass
0 items Sign In or Register
  • Home
  • IT Exams
  • Guarantee
  • FAQs
  • Reviews
  • Contact Us
  • Demo
Exam2pass > C++ Institute > C++ Programming > CPA-21-02 > CPA-21-02 Online Practice Questions and Answers

CPA-21-02 Online Practice Questions and Answers

Questions 4

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;

}

A.

It prints: 1

B.

It prints: 121

C.

It prints: 111

D.

It prints: 2

Buy Now

Correct Answer: B

Questions 5

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

}

}

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. 20

C. It prints: An exception occurred

D. It prints: float exception. Exception Nr. 5.2

Buy Now

Correct Answer: D

Questions 6

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

}

A. It prints: 0

B. It prints: 1

C. It prints: 2

D. It prints: 3

Buy Now

Correct Answer: A

Questions 7

Given:

#include

#include

using namespace std;

int main () {

try

{

int * myarray= new int[1000];

}

catch (bad_allocand)

{

cout << "Error allocating memory";

}

catch (exceptionand 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

Buy Now

Correct Answer: A

Questions 8

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

#include

#include

using namespace std;

int f(int i, int b);

int main()

{

int i=0;

i++;

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

{

cout<

}

return 0;

}

int f(int a, int b)

{

return a+b;

}

A. It prints: 202020

B. It prints: 012

C. It prints: 0

D. It prints: 2

Buy Now

Correct Answer: B

Questions 9

Which of the following statements may completely ignore their bodies (inner statements)? (Choose three.)

A. do

B. swicch

C. for

D. while

Buy Now

Correct Answer: BCD

Questions 10

What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are supplied as input?

#include

#include

using namespace std;

void f();

int main()

{

f();

return 0;

}

void f()

{

char c;

c = cin.get();

cout << c;

if(c != '\n')

f();

}

A. It prints: hello

B. It prints: olleh

C. It prints: h

D. It prints: o

Buy Now

Correct Answer: A

Questions 11

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

#include

#include

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

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

};

class B : public A {

public:

void set() {

y = 4; z = 2;

}

void Print() {

cout << y << z;

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

A. It prints: 42

B. It prints: 44

C. It prints: 22

D. It prints: 2

Buy Now

Correct Answer: A

Questions 12

Analyze the code below. If it contains an error, indicate its place in the program.

A. Error in the for loop

B. Error in the break statement

C. No error

D. Error in the if statement

Buy Now

Correct Answer: C

Questions 13

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

A. It prints: 3

B. It prints: 4

C. It prints: 0

D. It prints: 6

Buy Now

Correct Answer: D

Exam Code: CPA-21-02
Exam Name: CPA - C++ Certified Associate Programmer
Last Update: Jun 10, 2025
Questions: 257

PDF (Q&A)

$45.99
ADD TO CART

VCE

$49.99
ADD TO CART

PDF + VCE

$59.99
ADD TO CART

Exam2Pass----The Most Reliable Exam Preparation Assistance

There are tens of thousands of certification exam dumps provided on the internet. And how to choose the most reliable one among them is the first problem one certification candidate should face. Exam2Pass provide a shot cut to pass the exam and get the certification. If you need help on any questions or any Exam2Pass exam PDF and VCE simulators, customer support team is ready to help at any time when required.

Home | Guarantee & Policy |  Privacy & Policy |  Terms & Conditions |  How to buy |  FAQs |  About Us |  Contact Us |  Demo |  Reviews

2025 Copyright @ exam2pass.com All trademarks are the property of their respective vendors. We are not associated with any of them.