Exit demo CPA-21-02 CPA - C++ Certified Associate Programmer PDF format · free preview

C++ Institute CPA-21-02 - Questions & Answers

Free preview · every answer includes a full explanation

Product page: https://prepkeys.com/cpa-21-02.html

Question 1
Single choice

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

#include <iostream>

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

Question 2
Single choice

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

#include <iostream>

using namespace std;

int main()

{

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

y = &z;

cout<<x**y*x***y;

return 0;

}

A.

It prints: 36

B.

It prints: 14

C.

It prints: 16

D.

Compilation error

Question 3
Single choice

What is the output of the program?

#include <iostream>

using namespace std;

int main()

{

int tab[4]={10,20,30,40};

tab[1]=10;

int *p;

p=&tab[0];

cout<<*p;

return 0;

}

A.

It prints: 10

B.

It prints: 20

C.

It prints: 11

D.

It prints: 30

Question 4
Single choice

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

#include <iostream>
#include <string>
using namespace std;
class A {
int x;

protected:
int y;
public:
int z;
A() { x=1; y=2; z=3; }
};
class B : public A {
string z;
public:
void set() {
y = 4;
z = "John";
}
void Print() {
cout << y << z;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}

A.

It prints: 4John

B.

It prints: 2John

C.

It prints: 23

D.

It prints: 43

Question 5
Single choice

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

#include <iostream>
#include <string>
using namespace std;
class A {
public:
int x;
A() { x=0;}
};
class B {
public:
int x;
B() { x=1;}
};
class C :public A, public B {
public:
int x;
C(int x) {
this?>x = x;
A :x = x + 1;
}
void Print() { cout << x << A::x << B::x; }
};
int main () {
C c2(1);
c2.Print();

return 0;
}

A.

It prints: 1

B.

It prints: 121

C.

It prints: 111

D.

It prints: 2

Question 6
Single choice

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

#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int x,y;
union t
{
char tab[2];
int i;
};
union t u;
u.tab[0] = 1;
u.tab[1] = 2;
u.i = 0;
x = u.tab[0];
y = u.tab[1];
cout << x << "," << y << "," << u.i;
return 0;
}

A.

compilation fails

B.

It prints: 0,0,0

C.

It prints: 1,2,0

D.

None of these

Question 7
Single choice

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

#include <iostream>

using namespace std;

int main()

{

int x=2, *y;

y = &x;

cout << *y + x;

return 0;

}

A.

It prints: 1

B.

It prints: 2

C.

It prints: 4

D.

It prints: 0

Question 8
Single choice

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

#include <iostream>

using namespace std;

int main()

{

int x=0;

int *ptr;

ptr = &x;

cout<<x<<" "<<*ptr;

return 0;

}

A.

It prints: 0 0

B.

It prints address of ptr

C.

It prints: 1

D.

It prints: 2

Question 9
Multiple choice

Which of the following statements are correct about an array?

int tab[10];

A.

The array can store 10 elements.

B.

The expression tab[1] designates the very first element in the array.

C.

The expression tab[9] designates the last element in the array.

D.

It is necessary to initialize the array at the time of declaration.

Question 10
Single choice

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

#include <iostream>

#include <string>

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.~First();

}

A.

It prints: Text

B.

Compilation error

C.

Runtime error.

D.

None of these

Showing 10 of 257 questions · Unlock the full set