Interview Question

What is move semantics?

Move semantics permit resource transfer from objects that may be modified.

💡 Concept ✅ Quick Revision 🧠 C++

Answer

Move semantics let operations transfer resources from an expiring or explicitly movable object. • Rvalue references enable overloads that can modify the source object. • After a standard-library move, the source is valid but may have an unspecified value unless documented otherwise. • Moving can avoid expensive deep copies, but it is not guaranteed to be cheaper for every type.

💡 C++ Example

std::string source = "large value"; std::string destination = std::move(source);

⚡ Quick Revision

Move semantics permit resource transfer from objects that may be modified.