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: 6

Questions 51

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;

int z;

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

A(int a, int b) : x(a), y(b) { z = x ? y;}

void Print() {

cout << z;

}

};

int main () {

A a(2,5);

a.Print();

return 0;

}

Options:
A.

It prints: ?3

B.

It prints: 2

C.

It prints: 6

D.

It prints: 5

Questions 52

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

}

Options:
A.

It prints: 0 5

B.

It prints: 5 1

C.

It prints: 1 5

D.

It prints: 5 0

Questions 53

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

#include <iostream>

#include <string>

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

B(int s) { cout << "B int parameter";}

};

int main () {

A a2("Test");

B b1(10);

B b2(b1);

return 0;

}

Options:
A.

It prints: A no parametersA no parametersB string parameter

B.

It prints: A string parameterA no parametersB int parameterA object A parameter

C.

It prints: A no parametersB string parameter

D.

It prints: A no parametersA no parameters

Questions 54

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

Questions 55

Given:

#include <iostream>

#include <exception>

using namespace std;

int main () {

try

{

int * myarray= new int[1000];

}

catch (bad_alloc&)

{

cout << "Error allocating memory";

}

catch (exception& e)

{

cout << "Standard exception";

}

catch (...)

{

cout << "Unknown exception";

}

return 0;

}

What will happen if we use the operator “new” and the memory cannot be allocated?

Options:
A.

It prints: Error allocating memory

B.

It prints: Standard exception

C.

It prints: Unknown exception

D.

Compilation error

Questions 56

What will be the output of the program?

#include <iostream>

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

Questions 57

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

#include <iostream>

#include <exception>

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;

}

Options:
A.

It prints: My exception.

B.

It prints: 0

C.

It prints: 1

D.

Compilation error

Questions 58

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

Questions 59

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

#include <iostream>

#include <string>

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;

}

Options:
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

Questions 60

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

#include <iostream>

#include <string>

using namespace std;

int f(int i, int b);

int main()

{

int i=0;

i++;

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

{

cout<<f(0,i);

}

return 0;

}

int f(int a, int b)

{

return a+b;

}

Options:
A.

It prints: 202020

B.

It prints: 012

C.

It prints: 0

D.

It prints: 2