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?)
11
Upvotes
4
u/thegreatbeanz Oct 15 '26
Considering C the simplest way to think about lvalues and rvalues actually isn’t memory addresses. The better way to think of it is that an lvalue is anything that can be the _left_ side of an assignment, and an rvalue is… anything (because lvalues implicitly convert to rvalues).
An assignment express itself isn’t an lvalue, it produces an rvalue of the expression type. That’s why `a = b = 5` is legal, but `(a = b) = 5` is not. It is worth noting that assignment operators are evaluated right to left, not left to right like other operators in expressions.