The difference between these two typedef declarations
typedef struct tnode TNODE;
struct tnode {
int count;
TNODE *left, *right;
};
TNODE s, *sp;
and
typedef struct {
int a;
int b;
} ab_t;
.
is that in the second case you declared an unnamed structure. It means that within the structure you can not refer to it itself. For example you can not write fir example
typede struct {
int count;
TNODE *left, *right;
} TNODE;
because the name TNODE used in this member declaration
TNODE *left, *right;
is not declared yet.
But you can refer to the structure if the structure tag will have a name like
struct tnode {
int count;
struct tnode *left, *right;
};
because the name struct tnode was already declared.
Another difference is that to declare a pointer to a structure there is no need to have a complete definition of the structure. That is you may write
typedef struct tnode TNODE;
TNODE *sp;
struct tnode {
int count;
TNODE *left, *right;
};
Pay attention to that you may write a typedef declaration also the following way
struct tnode {
int count;
struct tnode *left, *right;
} typedef TNODE;