pointer

Does anyone know?
1
2
3
4
int x = 1;
int *p = &++x;       //ok !
int *q = &x++;      //gives an error :O


why the first pointer is ok but the second is an error?
Last edited on
Doesn't the compiler tell you?
it does but i dont really understand what he means :)
according to the compiler "x++" is not a "lvalue" :O
The compiler is correct. x++ is an rvalue expression, and it's impossible to take an address of an rvalue.

Simplifying, lvalue is an expression that identifies an object that exists in RAM, it has an address. rvalue is an expression that identifies a non-object value or a temporary object, which you can treat as if it only exists in the CPU, it has no address.
Last edited on
Topic archived. No new replies allowed.