Why use a pointer to a pointer in this 'handmade list'?

Viewed 214

We have a project in school, which, despite what the project is about, it involves the use of linked lists with this specific structure:

typedef struct _node {
    int contents;
    _node *next_node;
} *node;

Before the project, we were assigned a bunch of functions to learn to work with the list (push a node to the front or back of the list, count the amount of nodes, search for a specific node, etc).

It wasn't all that difficult, but when the teacher sent the base project (so that every one of us started in the same place), all of the functions involve passing a *node by reference. For example:

resultType functionName(node *list, ...) { ... }

I did all of the list functions previous to the project with void functions, because, as I understand at least, we are working with pointers, so, as long as you don't lose the memory address of the list header, you won't lose the content (and the rest of the list).

So... what is the point of passing a pointer to a pointer in this case? Is there something I'm missing? I asked my teacher and he didn't know how to explain (either that, or he is just as lost as me). I mean, the structure is already a pointer, so, why pass the address of the address of the list?

3 Answers
Related