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

Questions 41

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

#include <iostream>

#include

#include <string>

using namespace std;

int main(void)

{

string s;

s = "Test";

s.resize (s.size() ? 1);

cout<<s<<" "<

return 0;

}

Options:
A.

It prints: Test 4

B.

It prints: Test 3

C.

Compilation error

D.

It prints: Tes 3

Questions 42

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

#include <iostream>

#include <string>

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<<ob.age << " " << so.name;

}

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

Questions 43

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

#include <iostream>

using namespace std;

int main(){

int i = 1;

if (--i==1) {

cout << i;

} else {

cout << i-1;

}

return 0;

}

Options:
A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

It prints: 2

Questions 44

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

#include <iostream>

using namespace std;

int x=5;

static int y;

int i=0;

void static myFunction()

{

y=x++ + ++i;

}

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

{

x++;

myFunction();

cout<<y<<" "<

}

Options:
A.

Compilation fails

B.

It prints: 5 5 0

C.

It prints: 7 7 1

D.

It prints: 6 5 1

Questions 45

What is the output of the program?

#include <iostream>

#include <string>

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

Questions 46

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;

}

{

i=5;

cout << i;

}

cout<<i;

return 0;

}

Options:
A.

1010

B.

101010

C.

055

D.

None of these

Questions 47

What is the output of the program?

#include <iostream>

#include <string>

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

Questions 48

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

#include <iostream>

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

Questions 49

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

#include <iostream>

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

Questions 50

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

#include <iostream>

#include <string>

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