+ 1

Why dereference doesnt work with addresses directly?

when a pointer p=&var; why dont *p=*&var; ??? is it just the way they are defined??

3rd Jan 2017, 7:07 PM
Mourya Karan
Mourya Karan - avatar
3 Respuestas
+ 1
yeah... agreed. but what my point is... when a pointer p represents an adress, and *p gives its value, why does *&var, where &var is the address of variable var, give an error
4th Jan 2017, 2:02 AM
Mourya Karan
Mourya Karan - avatar
0
i think because the variable var has not always to be a pointer itself, and you can perform the * operator only on pointers. so *p = var should be correct if var is not a pointer i guess.
3rd Jan 2017, 10:48 PM
Alireza Bahram
Alireza Bahram - avatar
0
because var itself is perhaps not declared as a pointer but as normal variable.
4th Jan 2017, 7:33 AM
Alireza Bahram
Alireza Bahram - avatar