← 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;
}
- A.LRLL
- B.LRRL
- C.LLRL
- 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 →