What does this notation in C mean?

int *w; int **d; d = &w; 

What exactly stores ** d?

+4
source share
5 answers

Once assigned **d matches *w . d is a pointer to a pointer to an integer; the pointer to the integer to which it points is equal to w . So *d - w , and **d - *w .

+5
source

int ** represents a 'pointer to a pointer to an int ' (also known as a double pointer).

Now int *w just represents a pointer to int , so the assignment d = &w says: "assign the address w (which is itself a pointer / address) to d ".

+3
source

** d is the same as * w; * d is equal to the pointer value stored in w; because d is a pointer to a pointer to an int, you must dereference it twice to get the actual value.

+3
source

w stores the int address. d stores the address of the pointer to int (except that in this case it stores a random value because it does not get the assigned one), in this case the address is d.

+3
source

** d is a pointer to a pointer to int, so ** d will have the address of the pointer * w when u says d = & w, but if u did not say that d = & w and just declared int * w int ** d, it would not matter except: int * w is a pointer to int and int ** d is a pointer to a pointer to int, but would in no way claim that d would save addres from w.

0
source

All Articles