Leads4pass > C++ Institute > C++ Certified Professional Programmer > CPA-21-02 > CPA-21-02 Online Practice Questions and Answers

CPA-21-02 Online Practice Questions and Answers

Questions 4

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;

}

A. It will print:"el "

B. The code will not compile.

C. It will print:"Hello "

D. It will print garbage value

Buy Now
Questions 5

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

#include

using namespace std;

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

char *s = "ABCDEF";

cout << s+2;

return 0;

}

A. It prints: CDEF

B. It prints: ABCDEF

C. It prints: BCDEF

D. None of these

Buy Now
Questions 6

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

#include

using namespace std;

class A

{

public:

void Print(){ cout<<"A";}

};

class B:public A

{

public:

virtual void Print(){ cout<< "B";}

};

int main()

{

A *obj;

A ob1;

obj = andob1;

obj?>Print();

B ob2;

obj = andob2;

obj?>Print();

}

A. It prints: AB

B. It prints: AA

C. It prints: BA

D. It prints: BB

Buy Now
Questions 7

What is the output of the program?

#include

using namespace std;

class Base {

static int age;

public:

Base () {};

~Base () {};

void setAge(int a=10) {age = a;}

void Print() { cout << age;}

};

int Base::age=0;

int main () {

Base a,*b;

b = new Base();

a.setAge();

b?>setAge(20);

a.Print();

b?>Print();

return 0;

}

A. It prints: 2020

B. It prints: 1020

C. It prints: 20

D. It prints: 10

Buy Now
Questions 8

A condition expression used by if(), while(), and do-while() must evaluate to and only to:

A. an int type value

B. any value that can be treated as truth/falsehood

C. a float type value

D. a bool type value

Buy Now
Questions 9

Which code, inserted at line 19, generates the output "23"?

#include

#include

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:

int y;

void set() { y = 4; z = "John"; }

void Print() {

//insert code here

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

A. cout << y << z;

B. cout << y << A::z;

C. cout << A::y << A::z;

D. cout << B::y << B::z;

Buy Now
Questions 10

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

#include

using namespace std;

void fun(int*);

int main()

{

int *x;

int i=2;

x=andi;

fun(x);

cout<

return 0;

}

void fun(int *i)

{

*i = *i * *i;

}

A. It prints: 2

B. It prints: 4

C. It prints: 0

D. It prints: 1

Buy Now
Questions 11

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

#include

using namespace std;

class First

{

public:

virtual void Print(){ cout<<"from First";}

};

class Second:public First

{

public:

void Print(){ cout<< "from Second";}

};

void fun(First *obj);

int main()

{

First FirstObject;

fun(andFirstObject);

Second SecondObject;

fun(andSecondObject);

}

void fun(First *obj)

{

obj?>Print();

}

A. It prints: from First

B. It prints: from Firstfrom First

C. It prints: from Firstfrom Second

D. It prints: from Secondfrom Second

Buy Now
Questions 12

What is the output of the program?

#include

using namespace std;

#define PRINT(i) cout<

int main()

{

int y=2, z=3;

PRINT(y);

PRINT(z);

return 0;

}

A. It prints: 123

B. It prints: 23

C. It prints: 3

D. It prints: 2

Buy Now
Questions 13

What will be the output of the program?

#include

#include

using namespace std;

int fun(int);

int main()

{

float k=3;

k = fun(k);

cout<

return 0;

}

int fun(int i)

{

i++;

return i;

}

A. 3

B. 5

C. 4

D. 5

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

PDF (Q&A)

$49.99

VCE

$55.99

PDF + VCE

$65.99