What are move semantics, and how do they differ from copy semantics?

Last updated 21 June 2026

  • Copy semantics deep-copy the resource (heap memory, file handle) so both objects own separate data. Move semantics transfer ownership by stealing the pointer/handle, with no allocation.

  • Moves use the move constructor and operator=(T&&), which take an rvalue reference. Temporaries bind automatically, and std::move (just a cast) forces a move on an lvalue.

  • A moved-from source must be left valid but unspecified, so it can still be destroyed or reassigned safely.

  • https://www.geeksforgeeks.org/cpp/overloads-of-the-different-references-in-c/
  • https://dev.to/werner/move-semantics-vs-copy-semantics-pkb
All C++ interview questions