Search code examples
cpointerslvalue

Is a dereferenced pointer a valid lvalue?


Assuming the definition:

int i  = 10;
int *p = &i;

Why is *p a valid lvalue here:

*p+=10; 

Shouldn't *p evaluate to the value of the int stored at &i, ie. 10, and hence generate a "Not an lvalue" error?


Solution

  • An lvalue is an expression that refers to a region of storage that can be manipulated.

    *p is such an expression that refers to a region of storage. This is different than say 10+=10; because 10 doesn't refer to a region of storage like a variable would.