I am studying code examples from my professor in order to become better acquainted with linked data structures.
In our linked-list.c example the professor defines a
Consider this code:
#include
typedef struct {
int data;
struct node *next;
} Node;
int main()
{
Node a, b = {10, NULL};
a.next = &b;
printf("%d\n", a.next->data);
}
This won't compile. The compiler has no idea what a struct node
is, other than it exists. So you might change the definition in the struct to Node *next;
. The typedef isn't in scope before it's declared, so it still won't compile. The simple answer is to do as he said, use the node
tag after struct
, and it works fine.