Free CPA Exam Braindumps
C++ Certified Associate Programmer Questions 46–50 (page: 11)

Updated On: 9-Feb-2026

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

#include <iostream>
using namespace std;

int main(){
int i = 1;
if (--i==1) {
cout << i;
} else {
cout << i-1;
}
return 0;
}

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

Answer(s): C



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

#include <iostream>

using namespace std;

void fun(int &i);


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


void fun(int &i)
{
i+=2;
}

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

Answer(s): C



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

#include <iostream>
using namespace std;

int fun(int x);

int main() {
cout << fun(0);
return 0;
}

int fun(int x) {
if(x > 0)
return fun(x-1);
else
return 100;
}

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

Answer(s): C



What is the output of the program if character 2 is supplied as input?

#include <iostream>

using namespace std;

int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}

  1. It prints: float exception. Exception Nr.
  2. It prints: int exception. Exception Nr. 20
  3. It prints: An exception occurred
  4. It prints: float exception. Exception Nr. 5.2

Answer(s): D



What is the output of the program if character 4 is supplied as input?

#include <iostream>
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw 'a';
default:
cout<<"No exception";
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}

  1. It prints: float exception. Exception Nr.
  2. It prints: int exception. Exception Nr.
  3. It prints: An exception occurred
  4. It prints: No exception

Answer(s): D



Viewing page 11 of 45
Viewing questions 51 - 55 out of 220 questions


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

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