ProgrammingVery hardProduct-company placement · C++

What is printed?

What is printed?
int main() {
    const string s = "x";
    string t = std::move(s);
    cout << s << t;
}
  1. A. x
  2. B. xx
  3. C. Compile-time error: cannot move a const object
  4. D. t only; s is now empty

Correct answer: B. xx

std::move(s) yields a const string&&, which cannot bind to the move constructor's string&& parameter, so the copy constructor is used. s is left untouched: moving from a const object silently copies.

More OOP with C++ and Java questions

Exams that ask this topic