Free CPA-21-02 Exam Braindumps
CPA - C++ Certified Associate Programmer Questions 111–115 (page: 24)

Updated On: 9-Feb-2026

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

#include <iostream>

using namespace std;

class First
{
public:
void Print(){ cout<<"from First";}
};
class Second
{
public:
void Print(){ cout<< "from Second";}
};
int main()
{

Second t[2];
for (int i=0; i<2; i++)
t[i].Print();
}

  1. It prints: from First
  2. It prints: from Firstfrom First
  3. It prints: from Secondfrom Second
  4. It prints: from Second

Answer(s): C



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

#include <iostream>

using namespace std;

void fun(int*);

int main()
{
int *x;
int i=2;
x=&i;
fun(x);
cout<<i;
return 0;
}

void fun(int *i)
{
*i = *i * *i;
}

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

Answer(s): B



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

#include <iostream>
#include <string>

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 &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(1),c2(2),c3;
c3 = c1 + c2;
c3.Print();
}

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

Answer(s): C



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

#include <iostream>

using namespace std;

int main()
{
int i = 0;
do {
i++;
if (i==3)

break;
cout<<i;
}
while(i < 5);
return 0;
}

  1. It prints: 12
  2. It prints: 1
  3. It prints: 0
  4. No output

Answer(s): A



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

#include <iostream>

using namespace std;

int compare(int, int);

int main()
{
int x = compare(10, 20);
cout << x;
return 0;
}

int compare(int i, int j)
{
return i<j;

}

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

Answer(s): C



Viewing page 24 of 53
Viewing questions 116 - 120 out of 257 questions


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

AI Tutor AI Tutor 👋 I’m here to help!