5 Answers
5

As far as I understand, an lvalue is just a fancy term for an expression that you can assign to. In other words, if something can appear on the left side of a = operator, it is an lvalue. That means x is an lvalue, but &x is not - you can't re-assign the address of x to something else.

If you have a function like int* getIntPtr() then getIntPtr() isn't an lvalue (writing getIntPtr() = 5 doesn't make any sense), but *(getIntPtr()) is.

Edit: Apparently, it's not quite as easy. If x was defined as const, x would still be an lvalue (called a non-modifiable lvalue), even though you cannot assign to it. I'm not sure if there are other exceptions.

A closer approximation is that an lvalue is an expression that designates an object. The flaw in that definition is that, given int *ptr = NULL;, *ptr is still an lvalue.
–
Keith ThompsonAug 27 '11 at 19:17

An array is also an lvalue but you cannot assign to it.
–
R..Aug 27 '11 at 20:36

An l-value makes sense on the left side of an assignment. All l-values are also r-values. Whether memory is needed or not has little to do with it being an l-value. More to the point is whether it evaluates to a memory location where something can be stored.

The C standard doesn't use the term "rvalue" except in one footnote, where it says that it's merely "the value of an expression" (whereas an lvalue is the expression itself, if the expression designates an object). I personally find this a bit confusion, and inconsistent with the original meanings of the terms, but when discussing C it's best to use the term "lvalue" as the standard defines it.
–
Keith ThompsonAug 27 '11 at 19:20

this is not an answer, you're probably floating in the same lack of confidence as the op.
–
unkulunkuluAug 27 '11 at 19:21

Is the question really just "what is an lvalue?" If it were I think they would have found an answer by now.
–
OwenAug 27 '11 at 19:23

What is x exactly? It's a variable! In C, it is (conceptually) the name of a memory location where you can store values, with associated information about type and constness and maybe other things. &x is the address of that memory location. You can't store your information in the location's address. You store it in the location. Of course the compiler can optimize the code so the variable is only stored in a register, as long as the result behaves the same. But that doesn't change what the variable is conceptually.
–
Medo42Aug 27 '11 at 19:33

Just to be clear, I meant "what is x exactly" rhetorically. If you've ever tried designing a language, this is not a trivial question.
–
OwenAug 27 '11 at 19:36

To be clear :
First, int x doesn't reserves the space for the variable, it just notifies the compiler about the variable. The space is reserved and assigned when the value is assigned to it, i.e when we do x=5;.

Now, the question of L-Value and R-Value :

L-Value : It is something to which a constant value can be assigned.
So, yes x is a L-Value. Because we can do x=5;.
But &x is not a L-Value since we can-not do &x=5;. Similarly, 0xyyyy is the address and can be a R-Value but can-not be assigned so, it is not L-Value.