0

I am reading l-value and r-value in c++. It seems l value stands for locator value .

What is the full form of r-value?

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
MAG
  • 2,841
  • 6
  • 27
  • 47
  • 1
    I always thought it was literally `left-value` & `right-value` but no one uses the full terms because they're not quite true since casting to an r-value is possible. – George May 11 '22 at 09:57
  • 3
    The L and R originally was for the **L**eft-hand side of an assignment, and the **R**ight-hand side of an assignment, because that's how it was initially thought of: An l-value was something you could assign to, and an r-value was something you could not assign to. The terms no longer apply to that simple test, but are kept anyways. – Some programmer dude May 11 '22 at 09:57
  • 1
    "l" actually stands for "left" and "r" is for right: https://en.cppreference.com/w/cpp/language/value_category – wohlstad May 11 '22 at 09:57
  • 3
    lvalue / rvalue are the full terms, dont try to make sense from the name alone, as the answer says the names are historical. If you want to know what they are you need to read their definitions – 463035818_is_not_an_ai May 11 '22 at 09:59
  • "locator" is how C spec retcons it, because by the time C was created, it was no longer about assignment. But C spec also has no rvalues (just "non-lvalue expressions") – Cubbi May 12 '22 at 21:34

3 Answers3

4

From Value categories

an rvalue (so-called, historically, because rvalues could appear on the right-hand side of an assignment expression)

Tony Tannous
  • 14,154
  • 10
  • 50
  • 86
1

l-value is for left value and r-value is for right value. These two terms are used to refer to the expressions in an assignment operator.

For example: x = 7 Here l-value is expression x which will get the r-value .i.e. 7 after assignment.

1

The traditional terms were right-value and left-value - based on whichever side of an assignment operator they could appear. Those definitions are no more accurate enough to describe what we use in modern C++. An lvalue is a named object: an object that can officially be referenced via an identifier. While an rvalue is an anonymous object at the verge of death; it is essentially a temporary object born as a result of returning from a function call. Now if this new born temporary is bound to a reference (either const lvalue, or rvalue), it gets name and becomes an lvalue. When an automatic object is about to be returned by a function, however it is going to lose its name (identity) - but not its value - and hence become an rvalue. This thread can give a better grasp of the idea. There are other less discussed terms to notice too: glvalue, xvalue, prvalue.

Red.Wave
  • 2,790
  • 11
  • 17
  • 1
    You have a serious typo: `An rvalue is a named object: an object that can officially be referenced via an identifier.` – Sebastian May 11 '22 at 15:22
  • 1
    @Sebastian that is why its bad to declare identifiers with extremely similar names – Red.Wave May 11 '22 at 15:24