Pass4itsure > C++ Institute > C++ Institute Certifications > 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 complex{

double re, im;

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

complex operator?(complex andt);

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

};

complex complex::operator? (complex andt){

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

Buy Now
Questions 5

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

#include

using namespace std;

int op(int x, int y)

{

return x?y;

}

int op(int x, float y)

{

return x+y;

}

int main()

{

int i=1, j=2, k, l;

float f=0.23;

k = op(i, j);

l = op(j, f);

cout<< k << "," << l;

return 0;

}

A. It prints: ?1,?1

B. It prints: ?1,3

C. It prints: ?1,2

D. Compilation fails

Buy Now
Questions 6

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

Buy Now
Questions 7

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

#include

using namespace std;

class complex{

double re;

double im;

public:

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 = 3.0;

c1.print();

return 0;

}

A. It prints: 0 0

B. It prints: 1 1

C. It prints: 3 3

D. Compilation error

Buy Now
Questions 8

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

#include

using namespace std;

int fun(int x);

int main() {

cout << fun(0);

}

int fun(int x) {

if(x > 0)

return fun(x-1);

else

return 100;

}

A. It prints: 0

B. It prints: 10

C. It prints: 100

D. It prints: -1

Buy Now
Questions 9

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

#include

#include

using namespace std;

inline float sum(float a,float b)

{

return a+b;

}

int main()

{

float a,b;

a = 1.5; b = 3.4;

cout<

return 0;

}

A. It prints: 0

B. It prints: 4.9

C. It prints: 5

D. It prints: 4

Buy Now
Questions 10

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

}

}

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

B. It prints: int exception. Exception Nr. 20

C. It prints: An exception occurred

D. Compilation Error

Buy Now
Questions 11

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

Buy Now
Questions 12

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

#include

using namespace std;

class A

{

public:

virtual void Print()=0;

};

class B:public A

{

public:

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

};

int main()

{

B ob2;

A *obj;

obj = andob2;

obj?>Print();

}

A. It prints: B

B. It prints: A

C. It prints: AB

D. It prints: BA

Buy Now
Questions 13

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

#include

using namespace std;

int main()

{

int i=5;

switch(i)

{

case 1:

cout<<"Hello";

break;

case 2:

cout<<"world";

break;

case 3:

break;

default:

cout<<"End";

}

return 0;

}

A. It prints: Hello

B. It prints: world

C. It prints: End

D. It prints: Helloworld

Buy Now
Exam Code: CPA-21-02
Exam Name: CPA - C++ Certified Associate Programmer
Last Update: May 28, 2026
Questions: 257
10%OFF Coupon Code: SAVE10

PDF (Q&A)

$49.99

VCE

$55.99

PDF + VCE

$65.99