1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. What does std::move(x) actually do in C++?

Added 30 Nov -0001

What does std::move(x) actually do in C++?

  1. Marks x as const to prevent further modification
  2. Deallocates x and returns its old storage
  3. Casts x to an rvalue reference so it can be moved from Correct answer
  4. Transfers the bits of x immediately into the target object

Correct answer

C. Casts x to an rvalue reference so it can be moved from

13 views

MCQSEXAM

Explanation

std::move is only a static_cast to an rvalue reference; it performs no data transfer by itself, and the actual work happens in a move constructor or move assignment operator that takes the rvalue. If no such overload exists, the const-bound copy constructor is selected and a copy silently occurs. After a move, the source remains valid but unspecified, so it may be assigned or destroyed but should not be read for its old value.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs