Summer Special - 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: c4sdisc65

CPA-21-02 PDF

$38.5

$109.99

3 Months Free Update

  • Printable Format
  • Value of Money
  • 100% Pass Assurance
  • Verified Answers
  • Researched by Industry Experts
  • Based on Real Exams Scenarios
  • 100% Real Questions

CPA-21-02 PDF + Testing Engine

$61.6

$175.99

3 Months Free Update

  • Exam Name: CPA - C++ Certified Associate Programmer
  • Last Update: Sep 12, 2025
  • Questions and Answers: 257
  • Free Real Questions Demo
  • Recommended by Industry Experts
  • Best Economical Package
  • Immediate Access

CPA-21-02 Engine

$46.2

$131.99

3 Months Free Update

  • Best Testing Engine
  • One Click installation
  • Recommended by Teachers
  • Easy to use
  • 3 Modes of Learning
  • State of Art Technology
  • 100% Real Questions included

CPA-21-02 Practice Exam Questions with Answers CPA - C++ Certified Associate Programmer Certification

Question # 6

What is the output of the program?

#include

using namespace std;

class Base {

static int age;

public:

Base () {};

~Base () {};

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

void Print() { cout << age;}

};

int Base::age=0;

int main () {

Base a,*b;

b = new Base();

a.setAge();

b?>setAge(20);

a.Print();

b?>Print();

return 0;

}

A.

It prints: 2020

B.

It prints: 1020

C.

It prints: 20

D.

It prints: 10

Full Access
Question # 7

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

Full Access
Question # 8

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

CPA-21-02 question answer

A.

It prints: 3

B.

It prints: 4

C.

It prints: 0

D.

It prints: 6

Full Access
Question # 9

Which of the following is a user defined data type?

1:

struct person

{

char name[20];

int age;

};

2:

int l=2;

3:

enum color {red,blue, green};

D.

char c;

A.

1

B.

2

C.

3

D.

4

Full Access
Question # 10

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

CPA-21-02 question answer

A.

using namespace myNamespace1; using namespace myNamespace2;

B.

using namespace myNamespace1;

C.

using namespace myNamespace1::y; using myNamespace2::x;

D.

using namespace myNamespace2::y; using myNamespace1::x;

Full Access
Question # 11

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

#include

#include

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;

}

A.

It prints: 0

B.

It prints: 4.9

C.

It prints: 5

D.

It prints: 4

Full Access
Question # 12

Which of the following is a logical operator?

A.

&

B.

&&

C.

||

D.

!

Full Access
Question # 13

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

#include

using namespace std;

int op(int x, int y);

int main()

{

int i=2, j=2, k;

float f=0.3;

k = op(i, j);

cout<< k << "," << op(1, f);

return 0;

}

int op(int x, int y)

{

return x+y;

}

A.

It prints: 4,1

B.

It prints: 4,0.7

C.

It prints: 4,0

D.

It prints: 0,4

Full Access
Question # 14

Which code, inserted at line 5, generates the output "ABC"?

#include

using namespace std;

class A {

public:

//insert code here

};

class B:public A {

public:

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

};

class C:public B {

public:

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

};

int main()

{

A ob1;

B ob2;

C ob3;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

A.

void Print(){ cout<<"A";}

B.

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

C.

virtual void Print(string s){ cout<

D.

None of these

Full Access
Question # 15

What will be the output of the program?

#include

using namespace std;

int main()

{

const int y = 5;

const x = ?10;

cout<

return 0;

}

A.

?10 5

B.

5 ?10

C.

Compilation error

D.

None of these

Full Access
Question # 16

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

#include

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;

}

A.

It prints: 0 10

B.

It prints: 11

C.

Compilation error

D.

None of these

Full Access
Question # 17

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

#include

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;

}

A.

Error: in prototype declaration unknown struct person

B.

Error: in structure

C.

It prints: Steve 31

D.

None of these

Full Access
Question # 18

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 {

string z;

public:

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

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

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

A.

It prints: 4John

B.

It prints: 2John

C.

It prints: 23

D.

It prints: 43

Full Access
Question # 19

What will be the output of the program?

#include

#include

using namespace std;

int fun(int);

int main()

{

float k=3;

k = fun(k);

cout<

return 0;

}

int fun(int i)

{

i++;

return i;

}

A.

3

B.

5

C.

4

D.

5

Full Access
Question # 20

Which of the following statements are true? (Choose two.)

A.

Class A's friend's friend is also a friend of class A

B.

Friendship is inherited

C.

A class may be a friend of many classes

D.

A class may have many friends

Full Access
Question # 21

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

Full Access
Question # 22

What will happen if the memory cannot be allocated?

CPA-21-02 question answer

A.

The program will print: Standard exception

B.

The program will print: Unknown exception

C.

The program will cause a compilation error

D.

The program will print: Error allocating memory

Full Access
Question # 23

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;

}

B.

It prints: 1

C.

It prints: 121

D.

It prints: 111

E.

It prints: 2

Full Access
Question # 24

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(1) & fun(0);

cout << i;

return 0;

}

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

Compilation error

Full Access
Question # 25

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

Full Access
Question # 26

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

#include

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;

}

A.

It prints: 0

B.

It prints: 3

C.

It prints: 2

D.

It prints: 1

Full Access
Question # 27

Which of the following expressions decrement variable i by 2? (Choose two.)

A.

i &= 0x03;

B.

i –= 2;

C.

––i; i––;

D.

––i––;

Full Access
Question # 28

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

CPA-21-02 question answer

A.

It prints: 33

B.

It prints: –31

C.

It prints: –1–1

D.

It prints: –13

Full Access
Question # 29

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

{

Second t[2];

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

t[i].Print();

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Secondfrom Second

D.

It prints: from Second

Full Access
Question # 30

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

#include

using namespace std;

class First

{

public:

First() { cout << "Constructor";}

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

};

int main()

{

First FirstObject;

FirstObject.Print();

}

A.

It prints: Constructorfrom First

B.

It prints: Constructor

C.

It prints: from First

D.

None of these

Full Access
Question # 31

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

#include

#include

using namespace std;

class complex{

double re, im;

public:

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

complex operator?(complex &t);

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

};

complex complex::operator? (complex &t){

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

Full Access
Question # 32

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

Full Access
Question # 33

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.

Full Access
Question # 34

Which code, inserted at line 8, generates the output "0102020"?

#include

using namespace std;

class Base {

static int age;

public:

Base () {};

~Base () {};

//insert code here

void Print() { cout << age;}

};

int Base::age=0;

int main () {

Base a,*b;

b = new Base();

a.Print();

a.setAge(10);

a.Print();

b?>setAge();

a.Print();

b?>Print();

return 0;

}

A.

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

B.

void setAge() {age = 20;}

C.

void setAge() {age = 10;}

D.

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

Full Access
Question # 35

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

Full Access
Question # 36

What will the variable "age" 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;

}

};

A.

public

B.

private

C.

protected

D.

None of these

Full Access
Question # 37

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

#include

#include

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;

}

A.

cout << fun(" World");

B.

cout << fun(*ps);

C.

cout << fun("Hello");

D.

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

Full Access
Question # 38

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

#include

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;

}

A.

It prints: 210

B.

It prints: 110

C.

It prints: 010

D.

Compilation error

Full Access
Question # 39

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

Full Access
Question # 40

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

#include

#include

using namespace std;

class A {

public:

A() { cout << "A0 ";}

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

};

class B : public A {

public:

B() { cout << "B0 ";}

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

};

class C : private B {

public:

C() { cout << "C0 ";}

C(string s) { cout << "C1 ";}

};

int main () {

B b1;

C c1;

return 0;

}

A.

It prints: A0 B0 A0 B1 A0 C0 A0 C1

B.

It prints: B0 B1 C0 C1

C.

It prints: A0 B0 A0 B0 C0

D.

It prints: B0 B1

Full Access
Question # 41

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

#include

using namespace std;

int main(){

int i = 1;

for(i=10; i>-1; i/=2) {

if(!i)

break;

}

cout << i;

return 0;

}

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

Compilation error

Full Access
Question # 42

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

#include

#include

using namespace std;

class complex{

double re, im;

public:

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

complex operator+(complex &t);

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

};

complex complex::operator+ (complex &t){

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.

Garbage value

Full Access
Question # 43

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

Full Access
Question # 44

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

#include

#include

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;

}

A.

It prints: 0

B.

It prints: 6

C.

It prints: 2

D.

It prints: 3

Full Access
Question # 45

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

#include

using namespace std;

int main()

{

const int x=0;

const int *ptr;

ptr = &x;

cout<<*ptr;

return 0;

}

A.

It prints: 0

B.

It prints address of x

C.

It prints: 1

D.

Compilation error

Full Access
Question # 46

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

Full Access
Question # 47

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

#include

using namespace std;

void fun(int*);

int main()

{

int i=2;

fun(&i);

cout<

return 0;

}

void fun(int *i)

{

*i = *i**i;

}

A.

It prints: 1

B.

It prints: 4

C.

It prints: 10

D.

It prints: 0

Full Access
Question # 48

Point out an error in the program.

#include

using namespace std;

int main()

{

char s1[] = "Hello";

char s2[] = "world";

char *const ptr = s1;

*ptr = 'a';

ptr = s2;

return 0;

}

A.

No error

B.

Cannot modify a const object

C.

Compilation error at line 9

D.

None of these

Full Access
Question # 49

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

#include

using namespace std;

int main()

{

int i=2;

switch(i)

{

case 1:

cout<<"Hello";

case 2:

cout<<"world";

case 3:

cout<<"End";

} return 0;

}

A.

It prints: Hello

B.

It prints: world

C.

It prints: worldEnd

D.

It prints: End

Full Access
Question # 50

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

#include

using namespace std;

void fun(int &i);

int main()

{

int i=2;

fun(i);

cout<

return 0;

}

void fun(int &i)

{

i+=2;

}

A.

It prints: 2

B.

It prints: 0

C.

It prints: 4

D.

It prints: 16

Full Access
Question # 51

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

#include

using namespace std;

void fun(char*);

int main()

{

char t[4]={'0', '1', '2', '3'};

fun(&t[2]);

return 0;

}

void fun(char *a)

{

cout << *a;

}

A.

It prints: 2

B.

It prints: 21

C.

It prints: 00

D.

It prints: 02

Full Access
Question # 52

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

#include

#include

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

}

A.

It prints: Text

B.

Compilation error

C.

Runtime error.

D.

None of these

Full Access
Question # 53

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<

}

{

int i=5;

cout << i;

}

cout<

return 0;

}

A.

1010

B.

101010

C.

0510

D.

None of these

Full Access
Question # 54

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

Full Access
Question # 55

What is the output of the program?

#include

using namespace std;

int main()

{

int tab[4]={10,20,30,40};

tab[1]=10;

int *p;

p=&tab[0];

cout<<*p;

return 0;

}

A.

It prints: 10

B.

It prints: 20

C.

It prints: 11

D.

It prints: 30

Full Access
Question # 56

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

#include

using namespace std;

int main(){

int i = 1;

if (--i==1) {

cout << i;

} else {

cout << i-1;

}

return 0;

}

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

It prints: 2

Full Access
Question # 57

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

#include

#include

using namespace std;

class B;

class A {

int age;

public:

A () { age=5; };

friend class B;

};

class B {

string name;

public:

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

void Print(A ob) {

cout << name << ob.age;

}

};

int main () {

A a;

B b;

b.Print(a);

return 0;

}

A.

It prints: Bob5

B.

It prints: Bob

C.

It prints: 5

D.

None of these

Full Access
Question # 58

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

#include

using namespace std;

int main(){

int *i;

i = new int;

*i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4;

cout << *i;

return 0;

}

A.

It prints: 0

B.

It prints: 1

C.

It prints: 2

D.

It prints: 0.5

Full Access
Question # 59

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;

}

};

A.

public

B.

private

C.

protected

D.

None of these

Full Access
Question # 60

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

#include

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;

}

A.

It prints: 5 1.5

B.

It prints: 3.14 10

C.

Compilation error

D.

None of these

Full Access
Question # 61

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

CPA-21-02 question answer

A.

It prints: 1

B.

lt prints: 2

C.

It prints: 111

D.

It prints: 121

Full Access
Question # 62

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

#include

#include

using namespace std;

class complex{

double re, im;

public:

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

complex(double n) { re=n,im=n;};

complex(int m,int n) { re=m,im=n;}

complex operator+(complex &t);

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

};

complex complex::operator+ (complex &t){

complex temp;

temp.re = this?>re + t.re;

temp.im = this?>im + t.im;

return temp;

}

int main(){

complex c1(1),c2(2),c3;

c3 = c1 + c2;

c3.Print();

}

A.

It prints: 1 1.5

B.

It prints: 2 1.5

C.

It prints: 3 3

D.

It prints: 0 0

Full Access
Question # 63

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

#include

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;

}

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

Full Access
Question # 64

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

#include

using namespace std;

int main()

{

int a=5;

cout << ((a < 5) ? 9.9 : 9);

}

A.

It prints: 9

B.

It prints: 9.9

C.

Compilation error

D.

None of these

Full Access
Question # 65

Which of the following is a correct way to define the function fun() in the program below?

#include

#include

#include

using namespace std;

int main()

{

int a[2][2];

fun(a);

return 0;

}

A.

void fun(int *p[2]) {}

B.

void fun(int *p[2][2]) {}

C.

void fun(int *p[][2]) {}

D.

void fun(int p[][2]) {}

Full Access
Question # 66

What is the output of the program given below?

#include

using namespace std;

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

{

enum state { ok, error, warning};

enum state s1, s2, s3, s4;

s1 = ok;

s2 = warning;

s3 = error;

s4 = ok;

cout << s1<< s2<< s3<< s4;

return 0;

}

A.

1234

B.

compilation fails

C.

0210

D.

1322

Full Access
Question # 67

What is the expected result of the following program?

CPA-21-02 question answer

A.

It prints: ABCD

B.

It prints: ACBD

C.

It prints: ACDB

D.

It prints: CABD

Full Access
Question # 68

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

#include

using namespace std;

namespace myNamespace1

{

int x = 5;

int y = 10;

}

namespace myNamespace2

{

float x = 3.14;

float y = 1.5;

}

int main () {

namespace newname = myNamespace1;

using namespace newname;

cout << x << " ";

cout << y;

return 0;

}

A.

It prints: 5 1.5

B.

It prints: 3.14 1.5

C.

It prints: 5 10

D.

It prints: 5

Full Access
Question # 69

Which code, inserted at line 18, generates the output "AB"

#include

using namespace std;

class A

{

public:

void Print(){ cout<< "A";}

void Print2(){ cout<< "a";}

};

class B:public A

{

public:

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

void Print2(){ cout<< "b";}

};

int main()

{

B ob2;

//insert code here

ob2.Print();

}

A.

ob2?>A::Print();

B.

ob2.B::Print();

C.

ob2?>B::Print();

D.

ob2.A::Print();

Full Access
Question # 70

Which of the following operations is INCORRECT?

A.

int i=15;

B.

long int k=123

C.

float f=12,2;

D.

double d=12;

Full Access
Question # 71

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

CPA-21-02 question answer

A.

It causes a compilation error

B.

It prints: Tesc failed

C.

.It prints: failed

D.

It prints: Tesc

Full Access
Question # 72

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

#include

using namespace std;

int main()

{

int *a= new int;

*a=100;

cout << *a;

delete a;

}

A.

It prints: 1

B.

It prints: 100

C.

It prints: 0

D.

It prints: 10

Full Access
Question # 73

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

CPA-21-02 question answer

A.

It prints: 4

B.

It prints: 1

C.

It causes a compilation error

D.

lit prints: 0

Full Access
Question # 74

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

#include

using namespace std;

class A

{

public:

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

};

class B:public A

{

public:

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

};

int main()

{

A *obj;

A ob1;

obj = &ob1;

obj?>Print();

B ob2;

obj = &ob2;

obj?>Print();

}

A.

It prints: AB

B.

It prints: AA

C.

It prints: BA

D.

It prints: BB

Full Access
Question # 75

What happens if you try to compile and run this program?

#include

using namespace std;

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

{

print("Test");

return 0;

}

void print(int c[])

{

cout<

}

A.

It prints: Test

B.

Compilation fails

C.

Program terminates abnormally

D.

None of these

Full Access
Question # 76

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

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Firstfrom Second

D.

It prints: from Secondfrom Second

Full Access
Question # 77

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

#include

using namespace std;

int main()

{

int i=2;

switch(i)

{

case 1:

cout<<"Hello";

break;

case 2:

cout<<"world";

break;

case 3:

printf("End");

break;

}

return 0;

}

A.

It prints: Hello

B.

It prints: world

C.

It prints: End

D.

It prints: E

Full Access