W1038 L-Values and R-Values

From Coder Merlin
Jump to navigation Jump to search

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:

x=5+4

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:

print(x)

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:

5+4=x

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:

x=5+4

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.


CoderMerlin™ proudly recommends:
HintIcon.png

Your purchase via these links helps keep  Coder Merlin™ 's orbuculum ablaze. As an Amazon Associate we earn from qualifying purchases. Thank you for your support!


Designed with pride in Silicon Valley, CA, USA