Free CPA-21-02 Exam Braindumps (page: 8)

Page 8 of 65

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

#include <iostream>

using namespace std;

int x=5;
static int y=0;

void myFunction(int a)
{
y=++a;
}

int main (int argc, const char * argv[])
{
int i=0;

myFunction(i);
cout<<y<<" "<<x;
}

  1. It prints: 0 5
  2. It prints: 5 1
  3. It prints: 1 5
  4. It prints: 5 0

Answer(s): C



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

#include <iostream>
using namespace std;

class A {
public:
void Print(){ cout<<"A"; }
};
class B:public A {
public:
virtual void Print(){ cout<< "B"; }
};

class C:public B {
public:
void Print(){ cout<< "C"; }
};
int main()
{
A ob1;
B ob2;
C ob3;
A *obj;
obj = &ob1;
obj?>Print();
obj = &ob2;
obj?>Print();
obj = &ob3;
obj?>Print();
}

  1. It prints: BBB
  2. It prints: AAA
  3. It prints: ABC
  4. It prints: ABB

Answer(s): B



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

#include <iostream>
#include <string>
using namespace std;

class A {

public:
int x;
};

class B : public A {
public:
B() { x=1;}
B(int x) {this?>x = x;}
};

int main () {
B c1;
B c2(10);
cout << c1.x;
cout << c2.x;
return 0;

}

  1. It prints: 010
  2. It prints: 110
  3. It prints: 00
  4. It prints: 1

Answer(s): B



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

#include <iostream>

using namespace std;

void fun(char*);

int main()
{
char t[4]={'0', '1', '2', '3'};
fun(&t[2]);
return 0;
}
void fun(char *a)
{
cout << *a;

}

  1. It prints: 2
  2. It prints: 21
  3. It prints: 00
  4. It prints: 02

Answer(s): A



Page 8 of 65



Post your Comments and Discuss C++ Institute CPA-21-02 exam with other Community members:

Subash commented on October 21, 2024
I am planning to take this exam. Are these 257 questions enough to clear it? Also, does each section have a passing percentage, or is it based on the overall ?
INDIA
upvote