#I don't understand the syntax of structs
37 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
some1 explain why this is
why does
typedef struct name{
int thing
}
``` not work
and what the differences between the 3 are
casue thats not the syntax that C uses. syntax doesn't need a reason. syntax just is.
struct name {
int thing;
};
this is the actual struct syntax
and you have to do struct name variable_name; to create a variable with the struct type
but because people are lazy, they dont like typing struct everywhere
so you can use typedef to create an alternate name for the struct
like typedef the_type name;
so you can do typedef struct name name; and then you only need name variable_name; to use the struct
and then```c
typedef struct {
int thing;
} name;
is making name to mean the unnamed struct that you just declared
does that make sense?
this
struct name is the struct type, and then the second name is the new name for the type
oh wait what
so what if I did stuct cheese pizza
I doubt anyone would ever do that
but for learning purposes
how would I reference this?
pizza
if you had
struct cheese {
};
then struct cheese is how you refer to the cheese struct