An l-value, or location value, refers to an
expression that identifies a specific memory location and can generally be
used on the left-hand side of an assignment operator
(=). It represents the destination where a value can
be stored.
For example:
a = 3
In this statement, a is the
l-value because it represents the storage location where
the value is assigned. The value 3 is the
r-value because it is the value being assigned to
a.
l-values can generally be classified into two types:
A modifiable l-value refers to a storage location whose value can be changed. A normal variable is a common example.
int a;
a = 3;
a = 10;
Here, a is a modifiable l-value because its stored value can be
changed from 3 to 10.
A non-modifiable l-value identifies a storage location but
its stored value cannot be changed through normal assignment. A
const variable is a common example in
languages such as C and C++.
const int a = 3;
a = 10; // Invalid
Here, a refers to a storage location, but it cannot be
modified because it has been declared as const.
An l-value tells us where a value can be stored, while an r-value tells us what value is being stored or evaluated.
a = 3;
a → l-value → destination/location
3 → r-value → value being assigned