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

Page 22 of 65

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

#include <iostream>

using namespace std;

int main()
{
int x,y=10;
float f;
f = 5.20;

x=(int) f;
cout << x <<", ";
f=float (y);
cout << f;
return 0;
}

  1. It prints: 5, 10
  2. It prints: 5.2, 10
  3. It prints: 5.20, 10.0
  4. It prints: 5.2, 10.00

Answer(s): A



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



Page 22 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