In C, an object is anything that takes up storage. C 2011 online draft:
3. Terms, definitions, and symbols
...
3.15
1 object
region of data storage in the execution environment, the contents of which can represent values
An lvalue is an expression that designates an object such that the contents of that object may be read or modified (basically, any expression that can be the target of an assignment is an lvalue). While the C standard doesn't define the term variable, you can basically think of it as any identifier that designates an object:
int var;
The identifier var
designates an object that stores an integer value; the expression var
is an lvalue, since you can read and/or modify the object through it:
var = 10;
printf( "%d\n", var );
A pointer is any expression whose value is the location of an object. A pointer variable is an object that stores a pointer value.
int *p = &var;
The identifier p
designates an object that stores the location of an integer object. The expression &var
evaluates to the location (address) of the object var
. It is not an lvalue; it can't be the target of an assignment (you can't update an object's address). The operand of the unary &
operator must be an lvalue. The expression p
, OTOH, is an lvalue since you can assign a new value to it:
int y = 1;
p = &y;
printf( "%p\n", (void *) p ); // one of the few places in C you need to cast a void pointer
The expression *p
designates the object that p
points to (in this case, y
). It is also an lvalue, since you can assign to the object through it:
*p = 5; // same as y = 5
printf( "%d\n", *p );
So basically:
var
, p
, and y
are variables (identifiers designating objects)
var
, p
, *p
, and y
are lvalues (expressions through which an object may be read or modified)
&var
, p
, &p
&y
are pointer expressions (expressions whose values are locations of objects)
p
is a pointer variable (object that stores a pointer value)