W1038 L-Values and R-Values

From Coder Merlin

L-Values and R-Values[edit]

An L-Value refers to an object that persists beyond a single expression, that is, it is addressble. The name comes from the typical manner in which assignment statements are written in most programming languages, with the variable receiving the value on the left:


In this case, the variable "x" is an L-value which is being assigned the value 5+4, or 9. "x" refers to a location in memory which will contain the value 9, and that location will continue to persist after execution of this statement completes. For example, the next statement may again refer to "x", as in:


Note that in most computer languages, the variable to be assigned is on the left of the assignment operator. In these cases, it would not be possible to assign to a variable on the right, as in:


An R-Value refers to some object which does not persist after execution of the statement, that is, it is a temporary value. Think back to our original statement:


In this case, 5+4 is an R-Value. It isn’t possible to assign a value (that is, there is no persistent storage associated with) 5+4.

Designed with pride in Silicon Valley, CA, USA