Pass the C++ Institute C++ Certified Professional Programmer CPA-21-02 Questions and answers with CertsForce

Viewing page 7 out of 8 pages
Viewing questions 61-70 out of questions
Questions # 61:

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

#include

using namespace std;

class BaseClass

{

public:

int *ptr;

BaseClass(int i) { ptr = new int(i); }

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

void Print() { cout << *ptr; }

};

void fun(BaseClass x);

int main()

{

BaseClass o(10);

fun(o);

o.Print();

}

void fun(BaseClass x) {

cout << "Hello:";

}

Options:

A.

It prints: Hello:1


B.

It prints: Hello:


C.

It prints: 10


D.

Runtime error.


Expert Solution
Questions # 62:

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

#include

using namespace std;

int main()

{

int x=2, *y, z=3;

y = &z;

cout<

return 0;

}

Options:

A.

It prints: 36


B.

It prints: 14


C.

It prints: 16


D.

Compilation error


Expert Solution
Questions # 63:

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


Expert Solution
Questions # 64:

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;

}

Options:

A.

It prints: 0


B.

It prints address of x


C.

It prints: 1


D.

Compilation error


Expert Solution
Questions # 65:

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;

}

Options:

A.

It prints: 0


B.

It prints: 1


C.

It prints: -1


D.

Compilation error


Expert Solution
Questions # 66:

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;

}

Options:

A.

It prints: Bob5


B.

It prints: Bob


C.

It prints: 5


D.

None of these


Expert Solution
Questions # 67:

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

#include

using namespace std;

#define FUN(arg) if(arg) cout<<"Test";

int main()

{

int i=1;

FUN(i<3);

return 0;

}

Options:

A.

It prints: 0


B.

It prints: T


C.

It prints: T0


D.

It prints: Test


Expert Solution
Questions # 68:

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;

}

Options:

A.

It prints: 0


B.

It prints: 6


C.

It prints: 2


D.

It prints: 3


Expert Solution
Questions # 69:

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


Expert Solution
Questions # 70:

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


Expert Solution
Viewing page 7 out of 8 pages
Viewing questions 61-70 out of questions