Search code examples
cpointersstructpointer-to-pointer

How is &head of type pointer to pointer?


assuming we have a pointer called

struct node *head

When referring to this as &head the type becomes pointer to pointer (struct node**) why is this?


Solution

  • Imagine a real life laser pointer.

    You can point it to cars (car *), to pigeons (pigeon *), ..., to anything (void *).

    Now use a laser pointer to point to a laser pointer pointing to cars (car **).

    Of course in real life you can point the same laser to a car or a pigeon, etc... but in C that's invalid: a car * cannot point to pigeons, etc.

    You can turn the laser pointer off too (pointer = NULL; /* :-) */)