Weekend Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: xmas50

C++ Institute CPA-21-02 - CPA - C++ Certified Associate Programmer

Page: 4 / 8
Total 257 questions

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

#include

using namespace std;

int main(){

int i, j;

for(i = 0, j = 1; j < 2, i < 4; i++, j++);

cout << i << " " << j;

return 0;

}

A.

It prints: 4 5

B.

It prints: 2 3

C.

It prints: 3 2

D.

It prints: 4 3

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;

}

A.

It prints: 0

B.

It prints: 10

C.

It prints: 100

D.

It prints: -1

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

#include

using namespace std;

void set(struct person*);

struct person

{

int age;

};

int main()

{

struct person e = {18};

set(&e);

cout<< e.age;

return 0;

}

void set(struct person *p)

{

p?>age = p?>age + 1;

}

A.

It prints: 18

B.

It prints: 19

C.

It prints: 20

D.

It prints: 0

Given:

#include

#include

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?

A.

It prints: Error allocating memory

B.

It prints: Standard exception

C.

It prints: Unknown exception

D.

Compilation error

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

#include

#include

using namespace std;

int f(int i, int b);

int main()

{

int i=0;

i++;

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

{

cout<

}

return 0;

}

int f(int a, int b)

{

return a+b;

}

A.

It prints: 202020

B.

It prints: 012

C.

It prints: 0

D.

It prints: 2

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;

}

A.

It prints: Hello

B.

It prints: HelloWorld

C.

It prints: WorldHello

D.

It prints: WorldHelloWorld

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;

}

A.

It prints: Bob5

B.

It prints: Bob

C.

It prints: 5

D.

None of these

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

c1.print();

return 0;

}

A.

It prints: 1 0

B.

It prints: 1 1

C.

It prints: 1 2

D.

Compilation error

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

#include

#include

using namespace std;

class First

{

string *s;

public:

First() { s = new string("Text");}

~First() { delete s;}

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

};

int main()

{

First FirstObject;

FirstObject.Print();

FirstObject.~First();

}

A.

It prints: Text

B.

Compilation error

C.

Runtime error.

D.

None of these

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