Search⌘ K
AI Features

Rvalue and Lvalue References

Explore the differences between rvalue and lvalue references in Modern C++. Understand how temporary objects, naming, and memory addressability affect their usage. Learn how to declare references and the role of rvalue references in move semantics and perfect forwarding for improved resource management in embedded programming.

Rvalues and Lvalues

Rvalues are

  • Temporary objects
  • Objects without a name
  • Objects from which we can not get the address

If one of these characteristics holds for an object, it is an rvalue. On the other hand, values with a name and an address are lvalues.

  • Lvalues can be on the left side of an assignment operator.
  • Rvalues can only be on the right side of an assignment operator.

A few examples of rvalues:

int five= 5;
std::string a= std::string("Rvalue");
std::string b= std::string("R") + 
...