Is the following
typedef struct node {
int data;
struct node* next;
} node;
the only way one can define a struct
so that one needn't write out struct
inside of the rest of the program when using it?
Ie by the above struct
the following works just fine:
node* head = NULL;
But, is there another way to express the same struct
that is generally considered better?
No. You could also do:
struct node {
int data;
struct node* next;
};
typedef struct node node;
'Better' isn't really a qualifier that can be applied to these; to my knowledge there is no advantage to one or the other.
Nope! You're spot on. In C++ this isn't necessary, but in C some people (Linux kernel for example) where they prefer leaving things as structs ( see here )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.