ProgrammingModerateProduct-company placement · GATE CS

What is printed?

What is printed?
int a = 1, b = 2;
int& r = a;
r = b;
r = 5;
cout << a << b;
  1. A. 15
  2. B. 12
  3. C. 55
  4. D. 52

Correct answer: D. 52

A reference is bound once, at initialisation; r = b copies b's value (2) into a, it does not rebind r. r = 5 then sets a to 5, and b stays 2.

More OOP with C++ and Java questions

Exams that ask this topic