← Quiz: Move Semantics and rvalue References: all 10 questions
Quiz: Move Semantics and rvalue References · Question 9 of 10
What does this print? (code)
What does this print?
#include <iostream>
#include <string>
#include <utility>
using namespace std;
int main() {
string a = "placement";
string b = move(a);
cout << b.size() << " " << a.empty() << "\n";
return 0;
}
- A.9 0
- B.9 1
- C.0 1
- D.Compile error
Answer & explanation
Correct answer: 9 1
b took a's characters. The standard library leaves a moved-from string empty in practice (it is only promised to be valid), so empty() prints 1.
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 →