Pass4itsure > 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
Questions 5

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

#include

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;

}

}

A. It prints: 21

B. It prints: 012

C. It prints: 0

D. None of these

Buy Now
Questions 6

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

Buy Now
Questions 7

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

Buy Now
Questions 8

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

#include

using namespace std;

class Test {

float i,j;

};

class Add {

public:

int x,y;

Add (int a=3, int b=3) { x=a; y=b; }

int result() { return x+y;}

};

int main () {

Test test;

Add * padd;

padd = andtest;

cout << padd?>result();

return 0;

}

A. It prints: 6

B. It prints: 9

C. Compilation error

D. It prints: 33

Buy Now
Questions 9

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

A. It prints: 5.2110.0

B. It prints: 5.210.0

C. It prints: 52.10

D. It prints: 5210

Buy Now
Questions 10

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

Buy Now
Questions 11

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

A. It prints: 33

B. It prints: ?1

C. It prints: ??

D. It prints: ?3

Buy Now
Questions 12

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

cout << i;

return 0;

}

A. It prints: 0

B. It prints: 1

C. It prints: -1

D. Compilation error

Buy Now
Questions 13

What is the output of the program?

#include

#include

using namespace std;

int main()

{

string s1="World";

string s2;

s2="Hello" + s1;

cout << s2;

return( 0 );

}

A. It prints: HelloWorld

B. It prints: Hello

C. It prints: World

D. Compilation error

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

PDF (Q&A)

$49.99

VCE

$55.99

PDF + VCE

$65.99