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

Page 12 of 65

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

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

class B;

class A {
int age;
public:
A () { age=5; };
friend class B;
};

class B {
string name;
public:
B () { name="Bob"; };
void Print(A ob) {
cout << name << ob.age;
}
};

int main () {
A a;
B b;

  1. Print(a);
    return 0;
    }
  2. It prints: Bob5
  3. It prints: Bob
  4. It prints: 5
  5. None of these

Answer(s): A



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



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