🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Move Semantics and rvalue References: all 10 questions

Quiz: Move Semantics and rvalue References · Question 3 of 10

What does this print? (code)

What does this print?

#include <iostream>
#include <string>
#include <utility>
using namespace std;
void f(const string &) { cout << "L"; }
void f(string &&) { cout << "R"; }
int main() {
    string s = "x";
    f(s);
    f(s + "y");
    f(move(s));
    f(s);
    return 0;
}
  1. A.LRLL
  2. B.LRRL
  3. C.LLRL
  4. D.RRRL
Answer & explanation

Correct answer: LRRL

s is an lvalue (L), s + "y" is a temporary (R), move(s) is an rvalue (R), and s is still a named variable (L).

Can you get the rest right without peeking?

Take the timed Quiz: Move Semantics and rvalue References quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →