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

Free C++ Institute CPA-21-02 Practice Exam with Questions & Answers | Set: 2

Questions 11

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

#include <iostream>

using namespace std;

void print(char *c);

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

{

print("Test");

return 0;

}

void print(char *c)

{

cout<<c;

}

Options:
A.

It prints: Test

B.

It prints: T

C.

It prints: st

D.

None of these

Questions 12

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

CPA-21-02 Question 12

Options:
A.

It causes a compilation error

B.

It prints: Tesc failed

C.

.It prints: failed

D.

It prints: Tesc

Questions 13

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

#include <iostream>

using namespace std;

class Base {

int age;

public:

class C {

int b;

void PrintC() { cout << b; }

};

Base () {age=5;};

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

void Print() { cout << age;}

};

int main () {

Base a;

a.setAge(10);

a.Print();

return 0;

}

Options:
A.

It prints: 1020

B.

It prints: 105

C.

It prints: 10

D.

It prints: 20

Questions 14

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

#include <iostream>

#include <string>

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

Questions 15

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

#include <iostream>

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

}

Options:
A.

It prints: AB

B.

It prints: AA

C.

It prints: BA

D.

It prints: BB

Questions 16

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

#include <iostream>

using namespace std;

int f(int a, int b);

int main()

{

float b;

b = f(20,10);

cout << b;

return 0;

}

int f(int a, int b)

{

return a/b;

}

Options:
A.

It prints: 2

B.

It prints: 5

C.

It prints: 10

D.

It prints: 0

Questions 17

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

#include <iostream>

using namespace std;

int min(int a, int b);

int main()

{

int b=10;

b = min(5,20);

cout << b;

return 0;

}

int min(int a, int b)

{

if (a

return(a);

else

return(b);

}

Options:
A.

It prints: 10

B.

It prints: 20

C.

It prints: 5

D.

It prints: 0

Questions 18

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

CPA-21-02 Question 18

Options:
A.

It prints: 4

B.

It prints: 1

C.

It causes a compilation error

D.

lit prints: 0

Questions 19

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

#include <iostream>

using namespace std;

int fun(int x) {

return 2*x;

}

int main(){

int i;

i = fun(0.5) || fun(0);

cout << i;

return 0;

}

Options:
A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

Compilation error

Questions 20

Which code line inserted instead of the comment below will fix the program so that it produces the expected output and does not cause any memory leak?

CPA-21-02 Question 20

Options:
A.

delete [] p;

B.

delete p[];

C.

delete p;

D.

delete *p;