🎙 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 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;
}
  1. A.9 0
  2. B.9 1
  3. C.0 1
  4. 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 →