Structures with tags allow you to make a instances (or whatever an instance is called in c). What about typedef structs though? If the typedef is for the struct keyword to be replaced by a type name, then every time you use the the typename aren’t you just saying that you are replacing the struct keyword with the type name? Example:
typedef struct {
int x;
int y;
}TypeName;
int main()
{
TypeName instance; // isn't this the same as writing struct instance; ?
return 0;
}
So how does typedef work when you use it on a struct?
>Solution :
It defines a struct with no name and then make TypeName a name for that same struct.
If you like, you can imagine it as if the compiler creates a random name for you (some compilers actually do):
typedef struct __TOTALLY_RANDOM_NAME_wieryweuoi3u4t23423cogh234283 {
int x;
int y;
}TypeName;
int main()
{
struct __TOTALLY_RANDOM_NAME_wieryweuoi3u4t23423cogh234283 instance;
return 0;
}