Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a dereferenced pointer a valid lvalue?

Tags:

c

pointers

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?


1 Answers

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.

like image 53
SiegeX Avatar answered Sep 13 '25 20:09

SiegeX