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

Page: 1 / 14
Total 257 questions
Question 1

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

#include

#include

using namespace std;

class complex{

double re, im;

public:

complex() : re(1),im(0.4) {}

complex operator+(complex &t);

void Print() { cout << re << " " << im; }

};

complex complex::operator+ (complex &t){

complex temp;

temp.re = this?>re + t.re;

temp.im = this?>im + t.im;

return temp;

}

int main(){

complex c1,c2,c3;

c3 = c1 + c2;

c3.Print();

}



Answer : B


Question 2

What is the output of the program?

#include

using namespace std;

#define SQR(x)(x*x)

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

int x, y=2;

x = SQR(y);

cout << x << ", " <

return 0;

}



Answer : B


Question 3

Which statement should be added in the following program to make work it correctly?

using namespace std;

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

{

cout<<"Hello";

}



Answer : C


Question 4

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

#include

#include

using namespace std;

class A {

protected:

int y;

public:

int x,z;

A() : x(1), y(2), z(0) { z = x + y; }

A(int a, int b) : x(a), y(b) { z = x + y;}

void Print() { cout << z; }

};

class B : public A {

public:

int y;

B() : A() {}

B(int a, int b) : A(a,b) {}

void Print() { cout << z; }

};

int main () {

A b;

b.Print();

return 0;

}



Answer : A


Question 5

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

#include

#include

using namespace std;

void fun(int i);

int main()

{

int i=0;

i++;

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

{

fun(i);

}

return 0;

}

void fun(int i)

{

if (i==3)

return;

cout << i;

}



Answer : C


Question 6

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

#include

using namespace std;

int main()

{

int i=2;

switch(i)

{

case 1:

cout<<"Hello";

break;

case 2:

cout<<"world";

break;

case 3:

printf("End");

break;

}

return 0;

}



Answer : B


Question 7

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

#include

using namespace std;

int main()

{

const char *s;

char str[] = "Hello ";

s = str;

while(*s) {

cout << *++s;

*s++;

}

return 0;

}



Answer : A


Page:    1 / 14   
Total 257 questions