ProgrammingVery hardProduct-company placement · C++

What is printed?

What is printed?
void f(int&)  { cout << "L"; }
void f(int&&) { cout << "R"; }
int main() {
    int a = 1;
    int&& r = 5;
    f(a); f(5); f(std::move(a)); f(r);
}
  1. A. LRRR
  2. B. LRLL
  3. C. LLRR
  4. D. LRRL

Correct answer: D. LRRL

Lvalues bind to int&, rvalues (literals, std::move results) to int&&. A NAMED rvalue reference such as r is itself an lvalue expression, so f(r) calls the int& overload.

More OOP with C++ and Java questions

Exams that ask this topic