int *w;
int **d;
d = &w;
What does the **d store exactly?
int *w;
int **d;
d = &w;
What does the **d store exactly?
After the assignment, **d
is the same as *w
. d
is a pointer to a pointer to an integer; the pointer to an integer that it points to is w
. So *d
is w
, and **d
is *w
.
int **
represents 'a pointer to a pointer to an int
' (also known as a double pointer).
Now, int *w
simply represents a pointer to an int
, thus the assignment d = &w
is saying: "assign the address of w
(which is itself a pointer/address) to d
".
The value of **d is the same as the value of *w; *d is equal to the pointer value saved in w; because d is a pointer to a pointer to an int, you have to dereference it twice to get the actual value.
w stores the address of an int. d stores the address of a pointer to int (except in this case it stores a random value because it doesn't get assigned), in this case the address of d.
**d is a pointer to a pointer to an int, so **d would have the address of the pointer *w, when u say d=&w, but unless u have said that d=&w and just stated int *w int **d, it would have no meaning except for: int *w is a pointer to an int and int **d is a pointer to a pointer to an int, but in no way it would have stated that d will store the addres of w.