Winter Special Sale - Limited Time 60% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: 575363r9

Welcome To DumpsPedia

CPA-21-02 Sample Questions Answers

Questions 4

Which of the following operations is INCORRECT?

Options:

A.

int i=15;

B.

long int k=123

C.

float f=12,2;

D.

double d=12;

Buy Now
Questions 5

What will happen if the memory cannot be allocated?

Options:

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

Buy Now
Questions 6

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:

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

};

int main()

{

A *obj;

A ob1;

obj = &ob1;

obj?>Print();

B ob2;

obj = &ob2;

obj?>Print();

}

Options:

A.

It prints: AB

B.

It prints: AA

C.

It prints: BA

D.

It prints: BB

Buy Now
Questions 7

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;

}

}

Options:

A.

It prints: 21

B.

It prints: 012

C.

It prints: 0

D.

None of these

Buy Now
Questions 8

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;

}

Options:

A.

No error

B.

Cannot modify a const object

C.

Compilation error at line 9

D.

None of these

Buy Now
Questions 9

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;

}

Options:

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

Buy Now
Questions 10

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

#include

using namespace std;

int main()

{

const char *s;

char str[] = "Hello ";

s = str;

while(*s) {

cout << *++s;

*s++;

}

return 0;

}

Options:

A.

It will print:"el "

B.

The code will not compile.

C.

It will print:"Hello "

D.

It will print garbage value

Buy Now
Questions 11

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

#include

#include

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 12

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;

}

Options:

A.

It prints: 0

B.

It prints: 1

C.

It prints: 2

D.

It prints: 0.5

Buy Now
Questions 13

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

#include

#include

using namespace std;

class A {

public:

string s;

A(string s) { this?>s = s; }

};

class B {

public:

string s;

B (A a) { this?>s = a.s; }

void print() { cout<

};

int main()

{

A a("Hello world");

B b=a;

b.print();

}

Options:

A.

It prints: Hello world

B.

It prints: Hello

C.

Compilation error

D.

None of these

Buy Now
Questions 14

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;

}

Options:

A.

It prints: 2

B.

It prints: 0

C.

It prints: 4

D.

It prints: 16

Buy Now
Questions 15

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"; }

};

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 16

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;

}

Options:

A.

1010

B.

101010

C.

0510

D.

None of these

Buy Now
Questions 17

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

#include

using namespace std;

int getValue();

int main()

{

const int x = getValue();

cout<

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 18

How could you pass arguments to functions?

Options:

A.

by value

B.

by reference

C.

by pointer

D.

by void

Buy Now
Questions 19

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

#include

#include

using namespace std;

class B;

class A {

int age;

public:

A () { age=5; };

friend void Print(A &ob, B &so);

};

class B {

string name;

public:

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

//insert code here

};

void Print(A &ob, B &so) {

cout<

}

int main () {

A a;

B b;

Print(a,b);

return 0;

}

Options:

A.

friend void Print(A ob, B so);

B.

friend void Print(A &ob, B &so);

C.

friend void Print(A *ob, B *so);

D.

None of these

Buy Now
Questions 20

Point out an error in the program.

#include

using namespace std;

int main()

{

const int x=1;

int const *y=&x;

cout<<*y;

return 0;

}

Options:

A.

No error

B.

Error: unknown pointer conversion

C.

cannot convert from 'const int *' to 'int *const'

D.

Compilation error

Buy Now
Questions 21

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;

}

Options:

A.

1010

B.

100

C.

010

D.

None of these

Buy Now
Questions 22

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

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

using namespace std;

class First

{

public:

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

~First() { cout << "Destructor";}

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

};

int main()

{

First FirstObject;

FirstObject.Print();

}

Options:

A.

It prints: Constructorfrom First

B.

It prints: Constructorfrom FirstDestructor

C.

It prints: Constructorfrom FirstDestructorDestructor

D.

Compilation error at line 16

Buy Now
Questions 24

What is the output of the program?

#include

using namespace std;

class BaseC

{

int i;

public:

BaseC() { i=?1;}

BaseC(int i) { i=i; }

void seti(int a) { i = a; };

void Print() { cout << i; }

};

int main()

{

BaseC *o = new BaseC();

o?>seti(10);

o?>Print();

}

Options:

A.

It prints: 10

B.

It prints: ?1

C.

It prints: 0

D.

Compilation error

Buy Now
Questions 25

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

#include

using namespace std;

int op(int x, int y)

{

int i;

i = x + y;

return i;

}

int main()

{

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

k = op(i, j);

l = op(j, i);

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

return 0;

}

Options:

A.

It prints: 1,2

B.

It prints: ?1,1

C.

It prints: 1,1

D.

It prints: 3,3

Buy Now
Questions 26

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

#include

using namespace std;

#define A 1

int main()

{

#if A

cout<<"Hello";

#endif

cout<<"world";

return 0;

}

Options:

A.

It will print: Helloworld

B.

It will print: Hello

C.

It will print: world

D.

It will print: 0

Buy Now
Questions 27

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

Options:

A.

Error in the for loop

B.

Error in the break statement

C.

No error

D.

Error in the if statement

Buy Now
Questions 28

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

Options:

A.

It prints: 4

B.

It prints: 1

C.

It causes a compilation error

D.

lit prints: 0

Buy Now
Questions 29

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;

}

Options:

A.

It prints: 42

B.

It prints: 44

C.

It prints: 22

D.

It prints: 2

Buy Now
Questions 30

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

Options:

A.

It prints: 10

B.

It prints: 2+32+3

C.

It prints: 7

D.

It prints: 22+3

Buy Now
Questions 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.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();

}

Options:

A.

It prints: 1 1.5

B.

It prints: 2 1.5

C.

It prints: 3 3

D.

It prints: 0 0

Buy Now
Questions 32

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

}

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 33

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

Options:

A.

It causes a compilation error

B.

It prints: Tesc failed

C.

.It prints: failed

D.

It prints: Tesc

Buy Now
Questions 34

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;

}

Options:

A.

3

B.

5

C.

4

D.

5

Buy Now
Questions 35

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

#include

#include

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 36

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;

}

Options:

A.

It prints: 1

B.

It prints: 100

C.

It prints: 0

D.

It prints: 10

Buy Now
Questions 37

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

Options:

A.

It prints: 1

B.

It causes a compilation error

C.

It prints: -1

D.

It prints: 0

Buy Now
Questions 38

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

#include

#include

using namespace std;

int f(int i);

int main()

{

int i=0;

i++;

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

{

cout<

}

return 0;

}

int f(int a)

{

return a+a;

}

Options:

A.

It prints: 202020

B.

It prints: 012

C.

It prints: 024

D.

It prints: 0

Buy Now
Questions 39

Which code lines inserted independently instead of the comment will make the following program work correctly? (Choose three.)

Options:

A.

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

B.

int main (int c, char *v[])

C.

int main

D.

void main ()

Buy Now
Questions 40

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

Options:

A.

It prints: BAD

B.

It prints: BACD

C.

It prints: ABCD

D.

It prints: BAC

Buy Now
Questions 41

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

#include

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 42

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

#include

using namespace std;

int main()

{

int i = 4;

while(i >= 0) {

cout<

i??;

}

return 0;

}

Options:

A.

It prints:”43210”

B.

It prints:”3210”

C.

It prints: ”3210?1”

D.

None of these

Buy Now
Questions 43

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

Options:

A.

It prints: AAABDD

B.

It pints: AABD

C.

It prints: AABDD

D.

It causes a compilation error

Buy Now
Questions 44

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

Options:

A.

It prints: 13

B.

It prints: l

C.

It prints: 12

D.

It prints: 2

Buy Now
Questions 45

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

#include

using namespace std;

void print(char *c);

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

{

print("Test");

return 0;

}

void print(char *c)

{

cout<

}

Options:

A.

It prints: Test

B.

It prints: T

C.

It prints: st

D.

None of these

Buy Now
Questions 46

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

#include

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 47

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 48

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

#include

using namespace std;

int fun(int);

int main()

{

int *x = new int;

*x=10;

//insert code here

return 0;

}

int fun(int i)

{

return i*i;

}

Options:

A.

cout << fun(*x) ;

B.

cout << fun(10);

C.

cout << fun(5) ;

D.

cout << fun(y) ;

Buy Now
Questions 49

If a function, which is not a method, needs to save any value between its subsequent invocations, this can be done by: (Choose two.)

Options:

A.

setting a variable declared inside the function with the static modifier

B.

setting a parameter of the function

C.

setting a variable declared outside the function

D.

setting a variable declared inside the function without the static modifier

Buy Now
Questions 50

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

Options:

A.

~Base() ( delete this; }

B.

no additional code is needed

C.

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

D.

~Base() { delete ptr; }

Buy Now
Questions 51

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

#include

using namespace std;

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

{

enum state { ok, error, warning};

enum state s1, s2, s3;

s1 = ok;

s2 = warning;

s3 = error;

s4 = ok;

cout << s1<< s2<< s3;

return 0;

}

Options:

A.

It will print:”123”

B.

compilation error

C.

It will print:”021”

D.

It will print:”132”

Buy Now
Questions 52

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

#include

using namespace std;

int main()

{

int i = 0;

i++;

goto lab;

i++;

lab:

cout<

return 0;

}

Options:

A.

It prints: 0

B.

It prints: 34

C.

It prints: 1

D.

It prints: 3

Buy Now
Questions 53

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

Options:

A.

It prints: MaxNiels

B.

It prints: RobertMax

C.

It prints: RobertNiels

D.

It causes a compilation error

Buy Now
Questions 54

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

Options:

A.

a = b * c;

B.

return a = b * c;

C.

return a = b * *c;

D.

a = b * *c;

Buy Now
Questions 55

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;

}

Options:

A.

It prints: 4

B.

It prints: 0

C.

It prints: 3

D.

It prints: 2

Buy Now
Questions 56

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;

}

Options:

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]) {}

Buy Now
Questions 57

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;

}

Options:

A.

It prints: 0

B.

It prints: 4.9

C.

It prints: 5

D.

It prints: 4

Buy Now
Questions 58

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;

}

Options:

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
Questions 59

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

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

}

Options:

A.

It prints: 0

B.

It prints: 1

C.

It prints: 2

D.

It prints: 3

Buy Now
Questions 61

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<

}

{

i=5;

cout << i;

}

cout<

return 0;

}

Options:

A.

1010

B.

101010

C.

055

D.

None of these

Buy Now
Questions 62

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

#include

using namespace std;

int op(int x, int y);

int main()

{

float *pf;

float f=0.9;

pf=&f;

cout << op(1, *pf);

return 0;

}

int op(int x, int y)

{

return x*y;

}

Options:

A.

It prints: 0

B.

It prints: 0.5

C.

It prints: 1

D.

It prints: ?1

Buy Now
Questions 63

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

#include

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 64

Which code, inserted at line 14, generates the output "3.14 10"?

#include

using namespace std;

namespace myNamespace1

{

int x = 5;

int y = 10;

}

namespace myNamespace2

{

float x = 3.14;

float y = 1.5;

}

int main () {

//insert code here

cout << x << " " << y;

return 0;

}

Options:

A.

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

B.

using namespace myNamespace1;

C.

using namespace myNamespace1; using namespace myNamespace2;

D.

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

Buy Now
Questions 65

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

x=(int) f;

cout << x <<", ";

f=float (y);

cout << f;

return 0;

}

Options:

A.

It prints: 5, 10

B.

It prints: 5.2, 10

C.

It prints: 5.20, 10.0

D.

It prints: 5.2, 10.00

Buy Now
Questions 66

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 67

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

}

Options:

A.

Garbage value

B.

It prints: AlanAlan

C.

It prints: Alan

D.

It prints: Al

Buy Now
Questions 68

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;

}

};

Options:

A.

public

B.

private

C.

protected

D.

None of these

Buy Now
Questions 69

What is the output of the program?

#include

#include

using namespace std;

int main () {

string s1 = "Hello", s2 = "World";

s2 = s1 + s2;

cout << s2;

return 0;

}

Options:

A.

It prints: Hello

B.

It prints: HelloWorld

C.

It prints: WorldHello

D.

It prints: WorldHelloWorld

Buy Now
Questions 70

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

#include

using namespace std;

class complex{

double re;

double im;

public:

complex() : re(0),im(0) {}

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;

}

Options:

A.

It prints: 0 0

B.

It prints: 1 1

C.

It prints: 3 3

D.

Compilation error

Buy Now
Questions 71

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

#include

using namespace std;

int main()

{

float x=3.5,y=1.6;

int i,j=2;

i = x + j + y;

cout << i;

return 0;

}

Options:

A.

It prints: 7

B.

It prints: 6

C.

It prints: 7,1

D.

Compilation error

Buy Now
Questions 72

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

return 0;

}

int fun(int x) {

if(x > 0)

return fun(x-1);

else

return 100;

}

Options:

A.

It prints: 0

B.

It prints: 10

C.

It prints: 100

D.

It prints: -1

Buy Now
Questions 73

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

#include

#include

using namespace std;

class A {

public:

int x;

};

class B : public A {

public:

B() { x=1;}

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

};

int main () {

B c1;

B c2(10);

cout << c1.x;

cout << c2.x;

return 0;

}

Options:

A.

It prints: 010

B.

It prints: 110

C.

It prints: 00

D.

It prints: 1

Buy Now
Questions 74

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

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 75

What will be the output of the program?

#include

using namespace std;

int fun(int);

int main()

{

cout << fun(5);

return 0;

}

int fun(int i)

{

return i*i;

}

Options:

A.

25

B.

5

C.

0

D.

1

Buy Now
Questions 76

What is the output of the program?

#include

#include

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 77

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;

}

Options:

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

Buy Now
Exam Code: CPA-21-02
Exam Name: CPA - C++ Certified Associate Programmer
Last Update: Nov 16, 2024
Questions: 257
$64  $159.99
$48  $119.99
$40  $99.99
buy now CPA-21-02