Zach said:
int x;
x = 10;
here x is the lvalue (the object holding a value) and 10 is the rvalue
(the value being assigned to an object) correct?
The meanings of the terms "lvalue" and "rvalue" can be tricky.
Before C existed, the terms "lvalue" and "rvalue" referred to two
different ways of evaluating an expression. The 'l' and 'r' stand for
"left" and "right", as in the left and right sides of an assignment
statement. Evaluating an expression for its lvalue meant determining
what object it designates. Evaluting an expression for its rvalue
meant determining the value of the expression.
For example, given the declaration "int x;" evaluating the expression
``x'' would mean determining the object to which it refers -- without
accessing that object's value. In an exprssion like arr[func() + 3],
this can involve more than just resolving a name. Evaluating the
expression ``x'' for its rvalue would mean accessing the object to
obtain the value stored in it. Some expressions, such as ``x + 1'',
cannot be evaluated for their lvalues, because they don't refer to any
object.
The C standard changed the way the term "lvalue" is used, and almost
entirely dropped the term "rvalue". In C, an "lvalue" is not the
result of evaluating an expression, it's the expression itself. The
only mention of "rlvalue" is in a footnote, which says that it just
means the value of an expression. An expression that's not an lvalue
isn't referred to as a rvalue; it's just a non-lvalue expression.
An lvalue in C is basically an expression that designates an object.
Just to add to the frivolity, the C89/C90 standard's definition of
"lvalue" was worded incorrectly, and the C99 standard's revised
definition attempted to correct it but just made a mess of the whole
thing. (The mess is the result of trying to nail down case like *ptr,
where ptr is a pointer that doesn't currently point to an object.
*ptr is still an lvalue, but trying to use it as one invokes undefined
behavior. In two attempts, the standard has failed to express that
correctly.)
So in your statement:
x = 10;
the subexpression x is an lvalue, and is used as an lvalue, because it
designates the object named "x".
Given:
int x;
int y = 10;
x = y;
In the assignment, both subexpressions x and y are lvalues, because
they're both expressions that designate objects. But y is not being
used as an lvalue; it's in a context, the right hand side of an
assignment, that doesn't require an lvalue. So the fact that it's an
lvalue is incidental. The left side of an assignment is a context
that does require an lvalue, so this:
(x + 1) = y;
is illegal (a constraint violation).
Sorry to have to give such a long explanation, but your question
wasn't as simple as it appeared (or as it should be).