How can a linked list node be defined "recursively"?

  1. Create the struct pointed to by the pointer in the first struct, it contains an integer and a pointer to a struct of the same type.

This is where your reasoning is off. Creating a pointer to something does not automatically create the thing it's supposed to point at. So the fact the first object is created with a pointer in it, does not mean that the pointer will point to something valid. Just like if I write:

int *p;

It doesn't point to anything. The value of the pointer is indeterminate. I can initialize the pointer:

int *p = NULL;

And it still doesn't point at anything. But I can give it the address of something:

int i = 1;
int *p = &i;

And now is points at something. Same thing with the pointer in the node. The node can only be made to hold the address of some node, but it doesn't have to. This is why a linked list is not just the declaration of a node, but also of a set of functions (operations). It is those functions that are meant to make sure the list is in a valid state. That each node points at another, or at a well-defined terminator.

Tags:

C

Linked List