Leads4pass > C++ Institute > C++ Programming > CPA-21-02 > CPA-21-02 Online Practice Questions and Answers

CPA-21-02 Online Practice Questions and Answers

Questions 4

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

#include

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

Buy Now
Questions 5

What is the output of the program?

#include

#include

using namespace std;

struct Person {

int age;

};

class First

{

Person *person;

public:

First() {person = new Person;

person?>age = 20;

}

void Print(){

cout << person?>age;

}

};

int main()

{

First t[2];

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

t[i].Print();

}

A. It prints: 10

B. It prints: 2020

C. It prints: 22

D. It prints: 00

Buy Now
Questions 6

Which of the structures is incorrect?

1: struct s1{ int x; long int li; }; 2: struct s2{ float f; struct s2 *s; };

3:

struct s3{ float f; struct s3 s; };

A.

1

B.

2

C.

3

D.

2, 3

Buy Now
Questions 7

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

#include

using namespace std;

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

{

int tab[5]={1,2,3};

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

cout <

return 0;

}

A. compilation fails

B. It prints: 12300

C. It prints: 12345

D. It prints: 00000

Buy Now
Questions 8

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

#include

#include

using namespace std;

class Second;

class Base {

int age;

public:

Base () { age=5; };

friend void set(Base andob, Second andso);

void Print() { cout << age;}

};

class Second {

string name;

public:

friend void set(Base andob, Second andso);

void Print() { cout << name;}

};

void set(Base andob, Second andso) {

ob.age = 0; so.name = "Bill";

}

int main () {

Base a;

Second b;

set(a,b);

a.Print();

b.Print();

return 0;

}

A. It prints: 0Bill

B. Compilation error

C. It prints: Bill0

D. None of these

Buy Now
Questions 9

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

#include

using namespace std;

int f(int a, int b);

int main()

{

float b;

b = f(20,10);

cout << b;

return 0;

}

int f(int a, int b)

{

return a/b;

}

A. It prints: 2

B. It prints: 5

C. It prints: 10

D. It prints: 0

Buy Now
Questions 10

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

#include

#include

using namespace std;

int f(int i);

int main()

{

int i=0;

i++;

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

{

cout<

}

return 0;

}

int f(int a)

{

return a+a;

}

A. It prints: 202020

B. It prints: 012

C. It prints: 024

D. It prints: 0

Buy Now
Questions 11

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.3) {}

complex(double n) { re=n,im=n;};

complex(int m,int n) { re=m,im=n;}

complex operator+(complex andt);

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

};

complex complex::operator+ (complex andt){

complex temp;

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

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

return temp;

}

int main(){

complex c1(1),c2(2),c3;

c3 = c1 + c2;

c3.Print();

}

A. It prints: 1 1.5

B. It prints: 2 1.5

C. It prints: 3 3

D. It prints: 0 0

Buy Now
Questions 12

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

A. It prints: 33

B. It prints: ?1

C. It prints: ??

D. It prints: ?3

Buy Now
Questions 13

Which definitions are correct?

A. int age;

B. int double;

C. char c;

D. int char;

Buy Now
Exam Code: CPA-21-02
Exam Name: CPA - C++ Certified Associate Programmer
Last Update: Jan 15, 2025
Questions: 257
10%OFF Coupon Code: SAVE10

PDF (Q&A)

$49.99

VCE

$55.99

PDF + VCE

$65.99