Spring Sale Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: pass65

CPA-21-02 CPA - C++ Certified Associate Programmer Questions and Answers

Questions 4

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

#include < iostream >

#include < string >

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

};

class B : public A {

string name;

public:

void set() {

y = 2;

z = 3;

}

void Print() { cout < < y < < z; }

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Options:

A.

It prints: 123

B.

It prints: 000

C.

It prints: 23

D.

It prints: 12

Buy Now
Questions 5

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

#include < iostream >

using namespace std;

class A {

public:

int x;

A() { x=0;}

};

class B : public A {

public:

B() { x=1;}

};

class C : private B {

public:

C() { x=2;}

};

int main () {

C c1;

cout < < c1.x;

return 0;

}

Options:

A.

It prints: 210

B.

It prints: 110

C.

It prints: 010

D.

Compilation error

Buy Now
Questions 6

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

#include < iostream >

using namespace std;

int main()

{

int x=20;

int *ptr;

ptr = & x;

cout < < *ptr;

return 0;

}

Options:

A.

It prints: 20

B.

It prints: 0

C.

It prints address of ptr

D.

It prints: 2

Buy Now
Questions 7

Which of the following can be checked in a switch?case statement?

Options:

A.

char

B.

int

C.

enum

D.

double

Buy Now
Questions 8

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

#include < iostream >

using namespace std;

struct {

int x;

char c;

union {

float f;

int i;

};

} s;

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

{

s.x=10;

s.i=0;

cout < < s.i < < " " < < s.x;

}

Options:

A.

It prints: 0 10

B.

It prints: 11

C.

Compilation error

D.

None of these

Buy Now
Questions 9

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

#include < iostream >

using namespace std;

int main()

{

const int x=20;

const int *ptr;

ptr = & x;

*ptr = 10;

cout < < *ptr;

return 0;

}

Options:

A.

It prints: 20

B.

It prints: 10

C.

Compilation error at line 8

D.

It prints address of ptr

Buy Now
Questions 10

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

#include < iostream >

#include < string >

using namespace std;

class First

{

string *s;

public:

First() { s = new string( " Text " );}

~First() { delete s;}

void Print(){ cout < < *s;}

};

int main()

{

First FirstObject;

FirstObject.Print();

FirstObject.~First();

}

Options:

A.

It prints: Text

B.

Compilation error

C.

Runtime error.

D.

None of these

Buy Now
Questions 11

What is the output of the program if character 4 is supplied as input?

#include < iostream >

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;

}

Options:

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

Buy Now
Questions 12

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

#include < iostream >

using namespace std;

class A {

public :

void print() {

cout < < " A " ;

}

};

class B {

public :

void print() {

cout < < " B " ;

}

};

int main() {

B sc[2];

B *bc = (B*)sc;

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

(bc++)- > print();

return 0;

}

Options:

A.

It prints: A A

B.

It prints: B B

C.

It prints: A B

D.

It prints: B A

Buy Now
Questions 13

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

CPA-21-02 Question 13

Options:

A.

It prints: 10

B.

It prints: 2+32+3

C.

It prints: 7

D.

It prints: 22+3

Buy Now
Questions 14

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

#include < iostream >

using namespace std;

class First

{

public:

void Print(){ cout < < " from First " ;}

};

class Second

{

public:

void Print(){ cout < < " from Second " ;}

};

int main()

{

Second t[2];

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

t[i].Print();

}

Options:

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Secondfrom Second

D.

It prints: from Second

Buy Now
Questions 15

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

#include < iostream >

#include < string >

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;

}

Options:

A.

It prints: 05

B.

It prints: 012345

C.

It prints: 01245

D.

It prints: 0

Buy Now
Questions 16

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

#include < cstdlib >

#include < iostream >

using namespace std;

float* sum(float a,float b);

float* sum(float a,float b)

{

float *f = new float;

*f = a+b;

return f;

}

int main()

{

float a,b,*f;

a = 1.5; b = 3.4;

f = sum(a,b);

cout < < *f;

return 0;

}

Options:

A.

It prints: 0

B.

It prints: 4.9

C.

It prints: 5

D.

It prints: 4

Buy Now
Questions 17

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

#include < iostream >

using namespace std;

int compare(int, int);

int main()

{

int x = compare(10, 20);

cout < < x;

return 0;

}

int compare(int i, int j)

{

return i < j;

}

Options:

A.

It prints: 0

B.

It prints: 2

C.

It prints: 1

D.

It prints: 10

Buy Now
Questions 18

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

CPA-21-02 Question 18

Options:

A.

It prints: AAABDD

B.

It pints: AABD

C.

It prints: AABDD

D.

It causes a compilation error

Buy Now
Questions 19

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

#include < iostream >

#include < string >

using namespace std;

int main()

{

string s1[]= { " How " , " to " };

s1[0].swap(s1[1] );

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

cout < < s1[i];

}

return( 0 );

}

Options:

A.

It prints: Hoto

B.

It prints: toHow

C.

It prints: Ht

D.

It prints: to

Buy Now
Questions 20

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

CPA-21-02 Question 20

Options:

A.

It causes a compilation error

B.

It prints: Tesc failed

C.

.It prints: failed

D.

It prints: Tesc

Buy Now
Questions 21

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

CPA-21-02 Question 21

Options:

A.

a = b * c;

B.

return a = b * c;

C.

return a = b * *c;

D.

a = b * *c;

Buy Now
Questions 22

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

CPA-21-02 Question 22

Options:

A.

ob2.A::print();

B.

ob2 – > A::print();

C.

ob2.B::print();

D.

ob2 – > B::print();

Buy Now
Questions 23

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

#include < iostream >

using namespace std;

int main()

{

int *a= new int;

*a=100;

cout < < *a;

delete a;

}

Options:

A.

It prints: 1

B.

It prints: 100

C.

It prints: 0

D.

It prints: 10

Buy Now
Questions 24

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

CPA-21-02 Question 24

Options:

A.

It prints: 1

B.

It causes a compilation error

C.

It prints: -1

D.

It prints: 0

Buy Now
Questions 25

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

#include < iostream >

using namespace std;

int main(){

int i = 1;

if (i==1) {

cout < < i;

} else {

cout < < i-1;

}

return 0;

}

Options:

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

It prints: 2

Buy Now
Questions 26

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;

}

};

Options:

A.

public

B.

private

C.

protected

D.

None of these

Buy Now
Questions 27

Which of the following statements are correct about an array?

int tab[10];

Options:

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.

Buy Now
Questions 28

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

#include < iostream >

using namespace std;

void set(struct person*);

struct person

{

int age;

};

int main()

{

struct person e = {18};

set( & e);

cout < < e.age;

return 0;

}

void set(struct person *p)

{

p? > age = p? > age + 1;

}

Options:

A.

It prints: 18

B.

It prints: 19

C.

It prints: 20

D.

It prints: 0

Buy Now
Questions 29

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

#include < iostream >

#include < cstdarg >

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;

}

Options:

A.

It prints: 0

B.

It prints: 6

C.

It prints: 2

D.

It prints: 3

Buy Now
Questions 30

Which code, inserted at line 10, generates the output " Hello World " ?

#include < iostream >

#include < string >

using namespace std;

string fun(string, string);

int main()

{

string s= " Hello " ;

string *ps;

ps = & s;

//insert code here

return 0;

}

string fun(string s1, string s2)

{

return s1+s2;

}

Options:

A.

cout < < fun( " World " );

B.

cout < < fun(*ps);

C.

cout < < fun( " Hello " );

D.

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

Buy Now
Questions 31

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

#include < iostream >

using namespace std;

int main()

{

int x=2, *y;

y = & x;

cout < < *y + x;

return 0;

}

Options:

A.

It prints: 1

B.

It prints: 2

C.

It prints: 4

D.

It prints: 0

Buy Now
Questions 32

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

#include < iostream >

using namespace std;

void fun(int*);

int main()

{

int i=2;

fun( & i);

cout < < i;

return 0;

}

void fun(int *i)

{

*i = *i**i;

}

Options:

A.

It prints: 1

B.

It prints: 4

C.

It prints: 10

D.

It prints: 0

Buy Now
Questions 33

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

#include < iostream >

using namespace std;

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

{

int a = 30, b = 1, c = 5, i=10;

i = b < a < c;

cout < < i;

return 0;

}

Options:

A.

compilation fails

B.

It prints: 10

C.

It prints: 0

D.

It prints: 1

Buy Now
Questions 34

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

#include < iostream >

using namespace std;

int main()

{

int x=0;

int *ptr;

ptr = & x;

cout < < x < < " " < < *ptr;

return 0;

}

Options:

A.

It prints: 0 0

B.

It prints address of ptr

C.

It prints: 1

D.

It prints: 2

Buy Now
Questions 35

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

#include < iostream >

using namespace std;

namespace myNamespace1

{

int x = 5;

int y = 10;

}

namespace myNamespace2

{

float x = 3.14;

float y = 1.5;

}

int main () {

{

using namespace myNamespace1;

cout < < x < < " " ;

}{

using namespace myNamespace2;

cout < < y;

}

return 0;

}

Options:

A.

It prints: 5 1.5

B.

It prints: 3.14 10

C.

Compilation error

D.

None of these

Buy Now
Questions 36

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

#include < iostream >

#include < string >

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

}

Options:

A.

It prints: Sample text

B.

It prints: Sample

C.

It prints: text

D.

None of these

Buy Now
Questions 37

How many copies of the value member are stored in memory during program execution?

CPA-21-02 Question 37

Options:

A.

as many as objects of the A class plus one

B.

as many as obiects of the A class and its inheritants

C.

as many as objects of the A class

D.

one

Buy Now
Questions 38

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

#include < iostream >

#include < string >

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;

}

Options:

A.

It prints: 0Bill

B.

Compilation error

C.

It prints: Bill0

D.

None of these

Buy Now
Questions 39

If there is one, point out an error in the program

#include < iostream >

using namespace std;

int main()

{

int c = ' a ' ;

switch(i)

{

case ' 2 ' :

cout < < " OK " ;

case ' 1 ' :

cout < < " Error " ;

default:

break;

}

return 0;

}

Options:

A.

No Error

B.

Use of undeclared identifier ' i '

C.

Illegal use of ' continue '

D.

Illegal use of ' break '

Buy Now
Questions 40

Which code, inserted at line 19, generates the output " 23 " ?

#include < iostream >

#include < string >

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

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

};

class B : public A {

string z;

public:

int y;

void set() { y = 4; z = " John " ; }

void Print() {

//insert code here

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Options:

A.

cout < < y < < z;

B.

cout < < y < < A::z;

C.

cout < < A::y < < A::z;

D.

cout < < B::y < < B::z;

Buy Now
Questions 41

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

#include < iostream >

#include < string >

using namespace std;

class SampleClass

{

string *s;

public:

SampleClass() { s = new string( " Text " );}

SampleClass(string s) { this? > s = new string(s);}

~SampleClass() { delete s;}

void Print(){ cout < < *s;}

};

int main()

{

SampleClass *obj;

obj = new SampleClass( " Test " );

obj? > Print();

}

Options:

A.

It prints: Text

B.

It prints: Test

C.

It prints: TextTest

D.

Garbage value.

Buy Now
Questions 42

What is the output of the program given below?

#include < iostream >

using namespace std;

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

{

float f=?10.501;

cout < < (int)f;

}

Options:

A.

0

B.

11

C.

?10

D.

?11

Buy Now
Questions 43

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

#include < iostream >

using namespace std;

class A {

public:

virtual void Print()=0;

};

class B:public A {

public:

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

};

class C:public A {

public:

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

};

int main()

{

B ob2;

C ob3;

A *obj;

obj = & ob2;

obj? > Print();

obj = & ob3;

obj? > Print();

}

Options:

A.

It prints: BC

B.

It prints: CB

C.

It prints: CC

D.

It prints: BB

Buy Now
Questions 44

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

#include < iostream >

#include < string >

using namespace std;

class A {

protected:

int y;

public:

int x, z;

A() : x(1), y(2), z(0) {}

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

b.Print();

return 0;

}

Options:

A.

It prints: 10

B.

It prints: 2

C.

It prints: 5

D.

It prints: 1

Buy Now
Questions 45

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

#include < iostream >

using namespace std;

int mul (int a, int b=2)

{

int r;

r=a*b;

return (r);

}

int main ()

{

cout < < mul(1) < < mul(2,4);

return 0;

}

Options:

A.

It prints: 2

B.

It prints: 28

C.

It prints: 8

D.

It prints: 6

Buy Now
Questions 46

What is the output of the program if character “1” is supplied as input?

#include < iostream >

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;

}

Options:

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 47

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

#include < iostream >

using namespace std;

void set(struct person*);

struct person

{

char name[25];

int age;

};

int main()

{

struct person e = { " Steve " , 30};

set( & e);

cout < < e.name < < " " < < e.age;

return 0;

}

void set(struct person *p)

{

p? > age = p? > age + 1;

}

Options:

A.

Error: in prototype declaration unknown struct person

B.

Error: in structure

C.

It prints: Steve 31

D.

None of these

Buy Now
Questions 48

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

#include < iostream >

using namespace std;

int main() {

int i, j;

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

for(j = i; j < i + 1; j++)

if(j == i)

continue;

else

break;

}

cout < < j;

return 0;

}

Options:

A.

It prints: 0

B.

It prints: 3

C.

It prints: 2

D.

It prints: 1

Buy Now
Questions 49

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

CPA-21-02 Question 49

Options:

A.

It prints: 3.14

B.

It prints: Scring

C.

It causes a compilation error

D.

It prints: x

Buy Now
Questions 50

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

#include < iostream >

using namespace std;

class First

{

public:

virtual void Print(){ cout < < " from First " ;}

};

class Second:public First

{

public:

void Print(){ cout < < " from Second " ;}

};

void fun(First *obj);

int main()

{

First FirstObject;

fun( & FirstObject);

Second SecondObject;

fun( & SecondObject);

}

void fun(First *obj)

{

obj? > Print();

}

Options:

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Firstfrom Second

D.

It prints: from Secondfrom Second

Buy Now
Questions 51

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

CPA-21-02 Question 51

Options:

A.

It prints: 1

B.

It causes a compilation error

C.

It prints: -1

D.

It prints: 0

Buy Now
Questions 52

What is the output of the program given below?

#include < iostream >

using namespace std;

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

{

int i=10;

{

int i=0;

cout < < i;

}

{

int i=5;

cout < < i;

}

cout < < i;

return 0;

}

Options:

A.

1010

B.

101010

C.

0510

D.

None of these

Buy Now
Questions 53

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

#include < iostream >

#include < string >

using namespace std;

int main()

{

string s;

getline( cin, s );

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

return( 0 );

}

Options:

A.

It prints: test 4

B.

It prints: test

C.

It prints: test 5

D.

It prints: 4

Buy Now
Questions 54

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

#include < iostream >

using namespace std;

int main()

{

int x=2, *y, z=3;

y = & z;

cout < < x**y*x***y;

return 0;

}

Options:

A.

It prints: 36

B.

It prints: 14

C.

It prints: 16

D.

Compilation error

Buy Now
Questions 55

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

#include < iostream >

using namespace std;

int main(){

int i = 1;

if (--i==1) {

cout < < i;

} else {

cout < < i-1;

}

return 0;

}

Options:

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

It prints: 2

Buy Now
Questions 56

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

#include < iostream >

using namespace std;

void fun(int);

int main()

{

int a=0;

fun(a);

return 0;

}

void fun(int n)

{

if(n < 2)

{

fun(++n);

cout < < n;

}

}

Options:

A.

It prints: 21

B.

It prints: 012

C.

It prints: 0

D.

None of these

Buy Now
Questions 57

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

#include < iostream >

using namespace std;

int fun(int x) {

return x < < 2;

}

int main(){

int i;

i = fun(1) / 2;

cout < < i;

return 0;

}

Options:

A.

It prints: 0

B.

It prints: 1

C.

It prints: 2

D.

It prints: 4

Buy Now
Questions 58

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

#include < iostream >

using namespace std;

int getValue();

int main()

{

const int x = getValue();

cout < < x;

return 0;

}

int getValue()

{

return 5;

}

Options:

A.

It will print 0

B.

The code will not compile.

C.

It will print 5

D.

It will print garbage value

Buy Now
Questions 59

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

#include < iostream >

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 < < y < < " " < < x;

}

Options:

A.

It prints: 0 5

B.

It prints: 5 1

C.

It prints: 1 5

D.

It prints: 5 0

Buy Now
Questions 60

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

#include < iostream >

using namespace std;

int main()

{

int i=2;

switch(i)

{

case 1:

cout < < " Hello " ;

case 2:

cout < < " world " ;

case 3:

cout < < " End " ;

} return 0;

}

Options:

A.

It prints: Hello

B.

It prints: world

C.

It prints: worldEnd

D.

It prints: End

Buy Now
Questions 61

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

#include < iostream >

#include < string >

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;

}

Options:

A.

It prints: 3

B.

It prints: 0

C.

It prints: 1

D.

It prints: 2

Buy Now
Questions 62

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

#include < iostream >

using namespace std;

int main(){

int i, j;

for(i = 0, j = 1; j < 2, i < 4; i++, j++);

cout < < i < < " " < < j;

return 0;

}

Options:

A.

It prints: 4 5

B.

It prints: 2 3

C.

It prints: 3 2

D.

It prints: 4 3

Buy Now
Questions 63

What is the output of the program?

#include < iostream >

#include < string >

using namespace std;

int main()

{

string s1= " Hello " ;

string s2= " World " ;

s1+=s2;

cout < < s1;

return( 0 );

}

Options:

A.

It prints: HelloWorld

B.

It prints: Hello

C.

It prints: World

D.

It prints: HelWorld

Buy Now
Questions 64

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

#include < iostream >

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;

}

Options:

A.

It prints: A A

B.

It prints: B B

C.

It prints: A B

D.

It prints: B A

Buy Now
Questions 65

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

#include < iostream >

using namespace std;

void fun(int*);

int main()

{

int *x;

int i=2;

x= & i;

fun(x);

cout < < i;

return 0;

}

void fun(int *i)

{

*i = *i * *i;

}

Options:

A.

It prints: 2

B.

It prints: 4

C.

It prints: 0

D.

It prints: 1

Buy Now
Questions 66

What is the output of the program?

#include < iostream >

using namespace std;

#define PRINT(i) cout < < i;

int main()

{

int y=2, z=3;

PRINT(y);

PRINT(z);

return 0;

}

Options:

A.

It prints: 123

B.

It prints: 23

C.

It prints: 3

D.

It prints: 2

Buy Now
Questions 67

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

#include < iostream >

#include < string >

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:

int *tab;

B() { tab = new int[size]; for (int i=0; i < size; i++) tab[i]=1;}

B(string s) : A(s) { tab = new int[size]; for (int i=0; i < size; i++) tab[i]=1;}

~B() { delete tab; }

void Print() {

for (int i=0; i < size; i++) cout < < tab[i];

cout < < name;

}

};

int main () {

B b1( " Alan " );

B b2;

b1.tab[0]=0;

b1.Print(); b2.Print();

return 0;

}

Options:

A.

It prints: Alan

B.

It prints: 111

C.

It prints: 011Alan111Bob

D.

It prints: 0

Buy Now
Questions 68

What is the meaning of the following declaration? (Choose two.)

char **ptr;

Options:

A.

ptr is a pointer to a pointer to char

B.

ptr is a pointer to char*

C.

ptr is a pointer to a pointer to a pointer to char

D.

ptr is a pointer to char

Buy Now
Questions 69

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

#include < iostream >

using namespace std;

int main()

{

int i = 4;

while(i > = 0) {

cout < < i;

i??;

}

return 0;

}

Options:

A.

It prints:”43210”

B.

It prints:”3210”

C.

It prints: ”3210?1”

D.

None of these

Buy Now
Questions 70

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

#include < iostream >

using namespace std;

class A {

public:

int x;

A() { x=0;}

};

class B : protected A {

public:

int y;

using A::x;

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

void Print() { cout < < x < < y; }

};

int main () {

B b(5);

b.Print();

return 0;

}

Options:

A.

It prints: 05

B.

It prints: 0

C.

It prints: 5

D.

It prints: 15

Buy Now
Questions 71

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

CPA-21-02 Question 71

Options:

A.

It prints: 1

B.

lt prints: 2

C.

It prints: 111

D.

It prints: 121

Buy Now
Questions 72

What is the output of the program?

#include < iostream >

#include < string >

using namespace std;

int main()

{

string s1[]= { " H " , " t " };

string s;

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

s = s1[i];

if (i==0)

s.insert(1, " ow " );

else

s.push_back( ' o ' );

cout < < s;

}

return( 0 );

}

Options:

A.

It prints: Hoto

B.

It prints: Ht

C.

It prints: toHo

D.

It prints: Howto

Buy Now
Questions 73

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

#include < iostream >

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;

}

Options:

A.

It prints: ?1,?1

B.

It prints: ?1,3

C.

It prints: ?1,2

D.

Compilation fails

Buy Now
Questions 74

Which line of code inserted instead of the comment will make the following code run properly without causing memory leaks?

CPA-21-02 Question 74

Options:

A.

~Base() ( delete this; }

B.

no additional code is needed

C.

~Base() { delete ptr; delete ptr; }

D.

~Base() { delete ptr; }

Buy Now
Questions 75

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

CPA-21-02 Question 75

Options:

A.

It prints: 1

B.

It causes a compilation error

C.

It prints: 0

D.

It prints: My exception,

Buy Now
Questions 76

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

#include < iostream >

using namespace std;

int main()

{

int x,y=10;

float f;

f = 5.90;

cout < < f < < " , " ;

x=f;

cout < < x < < " , " ;

f=y;

cout < < f;

return 0;

}

Options:

A.

It prints: 5, 5, 10.00

B.

It prints: 5.9, 5, 10

C.

It prints: 6, 5, 10

D.

It prints: 6, 5, 10.00

Buy Now
Questions 77

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

#include < iostream >

#include < string >

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

};

class B : private A {

string name;

public:

void set() {

x = 1;

}

void Print() {

cout < < x;

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Options:

A.

It prints: 123

B.

It prints: 1

C.

It prints: ?123

D.

Compilation error

Buy Now
Exam Code: CPA-21-02
Exam Name: CPA - C++ Certified Associate Programmer
Last Update: Apr 30, 2026
Questions: 257

PDF + Testing Engine

$63.52  $181.49

Testing Engine

$50.57  $144.49
buy now CPA-21-02 testing engine

PDF (Q&A)

$43.57  $124.49
buy now CPA-21-02 pdf