Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

What Is an Lvalue and Rvalue in C++? Value Categories

C++
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedJul 24, 2023
UpdatedNov 17, 2026
6 min read

In C++, every expression has a value category. An lvalue is an expression that identifies an object with a persistent identity, such as a named variable, so you can take its address. An rvalue is an expression that is either a temporary (a prvalue) or an object marked as expiring (an xvalue), so its resources can be moved from. Since C++11 this distinction powers move semantics, rvalue references and perfect forwarding.

The old rule "lvalues go on the left of =, rvalues on the right" is only a rough guide. The precise model has five categories, and understanding it explains std::move, T&& and why a named rvalue reference is itself an lvalue.

Table of Contents

  • The value categories in C++11 and later
  • Lvalue examples
  • Rvalue examples and rvalue references
  • What std::move actually does
  • Forwarding references and std::forward
  • Guaranteed copy elision in C++17
  • Frequently Asked Questions
    • Is an lvalue always on the left of an assignment?
    • Why is a named rvalue reference an lvalue?
    • Does std::move move the object?
    • What is the difference between prvalue and xvalue?
  • Summary

The value categories in C++11 and later

The standard defines these categories:

CategoryMeaningExample
lvalueHas identity, cannot be moved from implicitlyx, *p, arr[0]
prvaluePure rvalue, initialises an object42, a + b, f() returning by value
xvalueHas identity, resources can be reusedstd::move(x), static_cast<T&&>(x)
glvaluelvalue or xvalue
rvalueprvalue or xvalue

A quick test: if you can take the address of the expression with &, it is an lvalue. If it is a temporary with no name, it is a prvalue.

Lvalue examples

cpp
text

In C++, even ++x is an lvalue (it refers to x), while x++ is a prvalue because it returns a copy of the old value.

Rvalue examples and rvalue references

Rvalues are temporaries you cannot take the address of:

cpp

An rvalue reference, written T&&, binds to rvalues. Overloading on const T& and T&& lets a function copy from lvalues and move from temporaries:

cpp
text

What std::move actually does

std::move does not move anything. It is a cast to an rvalue reference, static_cast<T&&>, which turns an lvalue into an xvalue so that a move constructor or move assignment can be selected. After you move from an object, leave it only for destruction or assignment, since it is in a valid but unspecified state.

A named rvalue reference is an lvalue, because it has a name:

cpp

Forwarding references and std::forward

In a template, T&& with a deduced T is a forwarding reference and can bind to both lvalues and rvalues. Use std::forward<T>(arg) to preserve the original category:

cpp

Guaranteed copy elision in C++17

Since C++17, a prvalue does not create a temporary that is then copied: it directly initialises the destination object. std::string s = make(); constructs the result in place, even if the type has no copy or move constructor. Avoid writing return std::move(local);, because it blocks this optimisation for named locals and triggers compiler warnings.

Frequently Asked Questions

Is an lvalue always on the left of an assignment?

No. An lvalue can appear on either side, and a const lvalue cannot be assigned to at all. What matters is that the expression has identity.

Why is a named rvalue reference an lvalue?

Because you can refer to it by name repeatedly, so using it as an rvalue automatically would be unsafe. Use std::move or std::forward when you want to pass it on as an rvalue.

Does std::move move the object?

No. It only casts to an rvalue reference. The move happens in the move constructor or move assignment operator that overload resolution then selects.

What is the difference between prvalue and xvalue?

A prvalue is a pure temporary value without identity. An xvalue is an existing object whose resources may be taken, typically the result of std::move.

Summary

In C++, lvalues have identity and a name or address, prvalues are temporaries, and xvalues are expiring objects that can be moved from. Rvalue references and std::move let you move rather than copy, forwarding references with std::forward preserve value category in templates, and C++17 guaranteed copy elision removes many copies entirely.

Share