struct vs typedef struct | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

struct vs typedef struct

What is the difference between: typedef struct Books { int book_id; } Book; and struct Book { int book_id; }; Both can be instantiated by Book book1, book2; Also, which one should be preferred, if there's a difference?

6th Feb 2018, 7:42 AM
Deepesh Choudhary
Deepesh Choudhary - avatar
1 Answer
+ 12
https://stackoverflow.com/questions/612328/difference-between-struct-and-typedef-struct-in-c Sounds to me like the struct keyword in C used to only define the struct object in the struct namespace, and hence typedef was used in place to create an alias to make it simpler to declare a struct object. Interesting, I never knew that.
6th Feb 2018, 8:06 AM
Hatsy Rei
Hatsy Rei - avatar