r/C_Programming • u/choosen_one007 • Oct 15 '26
Question Why are assignment expressions lvalues?
I was reading up about lvalues and understand them now as something that resolves to an address(memory location) in the program. So a variable x is an lvalue (because it is mapped to some address on the stack) and similarly *x , x[i], strings are all lvalues. But if this is the case why is an expression a = b , not an lvalue? Here the expression would assign b to a and then return a as evident in assignments like so: int c = a = b. (I know that the equals sign is right associative and hence this would get resolved as c = (a = b), but that doesn't really invalidate the fact that a = b resolves to an address in the program?)
View all comments
Show parent comment
2
u/thegreatbeanz Oct 15 '26 edited Oct 15 '26
To quote the C89 spec sub clause 3.2.2.1:
A difference of opinion within the C community has centered around the meaning
of lvalue, one group considering an lvalue to be any kind of object locator, another
group holding that an lvalue is meaningful on the left side of an assigning operator.
The Committee has adopted the definition of lvalue as an object locator. The term
modifiable lvalue is used for the second of the above concepts.
Happy to see that even after 37 years we can still disagree on this point ;P
Edit: I guess it is also worth adding the C99 footnote 53:
The name ‘‘lvalue’’ comes originally from the assignment expression E1 = E2, in which the left
operand E1 is required to be a (modifiable) lvalue. It is perhaps better considered as representing an
object ‘‘locator value’’. What is sometimes called ‘‘rvalue’’ is in this International Standard described
as the ‘‘value of an expression’’.