Explain the difference between an lvalue and an rvalue. Why was the concept of rvalue references introduced in C++11?
Last updated
An lvalue has identity and an address (a named variable). An rvalue is a temporary or pure value about to expire (a literal,
a + b).C++11 rvalue references (
T&&) let code detect temporaries and steal their resources instead of deep-copying, enabling move semantics and perfect forwarding.A named rvalue reference is itself an lvalue, so
std::moveis needed to pass it on as an rvalue.