MAG
MAG

Reputation: 3075

What is the full form of l-value and r-value in C++?

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?

Upvotes: 0

Views: 1562

Answers (3)

Red.Wave
Red.Wave

Reputation: 4251

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.

Upvotes: 2

Talha Asghar
Talha Asghar

Reputation: 116

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.

Upvotes: 1

Tony Tannous
Tony Tannous

Reputation: 14851

From Value categories

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

Upvotes: 4

Related Questions