In Week 5 Linked Lists/etc... are talked about.

In the stacks/queue's the structs are defined like:

typedef struct
   int size;
   int capacity;

whereas he defines the "node" struct as:

typedef struct node
   int n;
   struct node *next;

whats the point of saying node after the first typedef struct node? I don't understand? or is it just because we declare "struct node" within the node declaration anyways?

1 Answer 1


I found Rob's explanation in this video (starting around 6:40) helpful.

He says:

we need the identifier next to struct if the definition of the struct is recursive. .... This struct is recursive, since the definition of struct node contains within it a pointer to a struct node. Notice that we have to say struct node* next inside of the definition of the struct node, since the type def hasn't finished yet to allow us to simplify this to just node * next.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .