Free CPA Exam Braindumps
C++ Certified Associate Programmer Questions 86–90 (page: 19)

Updated On: 9-Feb-2026

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

#include <iostream>

using namespace std;

int op(int x, int y)
{
return x?y;
}


int op(int x, float y)
{
return x+y;
}


int main()
{
int i=1, j=2, k, l;
float f=0.23;
k = op(i, j);
l = op(j, f);
cout<< k << "," << l;
return 0;
}

  1. It prints: ?1,?1
  2. It prints: ?1,3
  3. It prints: ?1,2
  4. Compilation fails

Answer(s): C



Which of the following statements are correct?

  1. A function can be defined inside another function
  2. A function may have any number of return statements each returning different values.
  3. A function can return floating point value
  4. In a function two return statements should never occur.

Answer(s): B,C



Which code, inserted at line 15, generates the output "5 Bob"?

#include <iostream>
#include <string>
using namespace std;
class B;
class A {
int age;
public:
A () { age=5; };
friend void Print(A &ob, B &so);
};
class B {
string name;
public:
B () { name="Bob"; };
//insert code here
};


void Print(A &ob, B &so) {
cout<<ob.age << " " << so.name;
}


int main () {
A a;
B b;
Print(a,b);
return 0;
}

  1. friend void Print(A ob, B so);
  2. friend void Print(A &ob, B &so);
  3. friend void Print(A *ob, B *so);
  4. None of these

Answer(s): B



What is the output of the program if characters 't', 'e', 's' and 't' enter are supplied as input?

#include <iostream>
#include <string>

using namespace std;

int main()
{
string s;
getline( cin, s );
cout << s << " " << s.length();
return( 0 );
}

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

Answer(s): A



What happens if character 3 is entered as input?

#include <iostream>
using namespace std;
class A {
public:
int i;
};
int main () {
int c;
A obj;
obj.i = 5;
cin >> c;
try
{
switch (c)
{
case A. throw 20;
case B. throw 5.2f;
case C. throw obj;
default: cout<<"No exception";
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (A e)
{ cout << "object exception. Exception Nr. " << e.i; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}

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

Answer(s): A



Viewing page 19 of 45
Viewing questions 91 - 95 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!