goe
goe

Reputation: 5435

What does this notation mean in C?

int *w;
int **d;

d = &w;

What does the **d store exactly?

Upvotes: 4

Views: 1087

Answers (5)

Anand
Anand

Reputation: 1

**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.

Upvotes: 0

Michael Ekstrand
Michael Ekstrand

Reputation: 29120

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.

Upvotes: 5

sepp2k
sepp2k

Reputation: 370465

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.

Upvotes: 3

Jack Lloyd
Jack Lloyd

Reputation: 8405

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.

Upvotes: 3

Noldorin
Noldorin

Reputation: 147471

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".

Upvotes: 3

Related Questions