Weekend Sale 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: sale65best

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

Questions 21

What will be the output of the program?

#include <iostream>

#include <string>

using namespace std;

int fun(int);

int main()

{

float k=3;

k = fun(k);

cout<<k;

return 0;

}

int fun(int i)

{

i++;

return i;

}

Options:
A.

3

B.

5

C.

4

D.

5

Questions 22

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

#include <iostream>

using namespace std;

int main()

{

int i = 4;

while(i >= 0) {

cout<<i;

i??;

}

return 0;

}

Options:
A.

It prints:”43210”

B.

It prints:”3210”

C.

It prints: ”3210?1”

D.

None of these

Questions 23

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

#include <iostream>

using namespace std;

int main()

{

int i = 5;

cout<<"Hello World" << ++i;

return 0;

}

Options:
A.

It prints: Hello World6

B.

It prints: Hello

C.

It prints: World

D.

It prints: Hello World5

Questions 24

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

#include <iostream>

#include <string>

using namespace std;

class A {

public:

int age;

A () { age=5; };

};

class B : private A {

string name;

public:

B () { name="Bob"; };

void Print() {

cout << name << age;

}

};

int main () {

B b,*ob;

ob = &b;

ob?>age = 10;

ob?>Print();

return 0;

}

Options:
A.

It prints: Bob55

B.

It prints: Bob1

C.

It prints: 10

D.

Compilation error

Questions 25

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

CPA-21-02 Question 25

Options:
A.

It prints: 10

B.

It prints: 2+32+3

C.

It prints: 7

D.

It prints: 22+3

Questions 26

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

#include <iostream>

using namespace std;

int main() {

int i, j;

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

for(j = i; j < i + 1; j++)

if(j == i)

continue;

else

break;

}

cout << j;

return 0;

}

Options:
A.

It prints: 0

B.

It prints: 3

C.

It prints: 2

D.

It prints: 1

Questions 27

How many copies of the value member are stored in memory during program execution?

CPA-21-02 Question 27

Options:
A.

as many as objects of the A class plus one

B.

as many as obiects of the A class and its inheritants

C.

as many as objects of the A class

D.

one

Questions 28

Which code line inserted instead of the comment below will cause the program to produce the expected output?

CPA-21-02 Question 28

Options:
A.

using namespace myNamespace1; using namespace myNamespace2;

B.

using namespace myNamespace1;

C.

using namespace myNamespace1::y; using myNamespace2::x;

D.

using namespace myNamespace2::y; using myNamespace1::x;

Questions 29

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

#include <iostream>

#include <string>

using namespace std;

int main()

{

string s1[]= {"H" , "t" };

string s;

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

s = s1[i];

s.insert(1,"o");

cout << s;

}

return( 0 );

}

Options:
A.

It prints: Hoto

B.

It prints: Ho

C.

It prints: to

D.

It prints: Ht

Questions 30

What is the output of the program?

#include <iostream>

#include <string>

using namespace std;

int main()

{

char str[] = "Hello\0\World\0";

cout << str;

return 0;

}

Options:
A.

It prints: Hello

B.

It prints: World

C.

It prints: HW

D.

It prints: World\0World