C++ Institute CPA - C++ Certified Associate Programmer CPA-21-02 Exam Practice Test

Page: 1 / 14
Total 257 questions
Question 1

Which definitions are correct?



Answer : A, C


Question 2

What happens if character 3 is entered as input?

#include

using namespace std;

class A {

public:

int i;

};

int main () {

int c;

A obj;

obj.i = 5;

cin >> c;

try

{

switch (c)

{

case



Answer : A, A


Question 3

What is the output of the program?

#include

using namespace std;

int main()

{

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

tab[1]=10;

int *p;

p=&tab[0];

cout<<*p;

return 0;

}



Answer : A


Question 4

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

#include

using namespace std;

int main()

{

int x=0;

int *ptr;

ptr = &x;

cout<

return 0;

}



Answer : A


Question 5

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;

c1.print();

return 0;

}



Answer : C


Question 6

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

#include

using namespace std;

void fun(int);

int main()

{

int a=0;

fun(a);

return 0;

}

void fun(int n)

{

if(n < 2)

{

fun(++n);

cout << n;

}

}



Answer : A


Question 7

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

#include

#include

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<

}

int main () {

A a;

B b;

Print(a,b);

return 0;

}



Answer : B


Page:    1 / 14   
Total 257 questions