I need some assistance understanding how variables of a typedef work with structs
/*This is the Struct, with a new type Program*/
typedef struct prog{
char move[MAXNUMTOKENS][MAXTOKENSIZE];
int cm;
}Program;
Program prog; // new variable of type Program that has an array and an int
My question is what does this next statement do, does it initialize the int cm in the structs to zero ?
prog.cm=0;
Think of a struct as a template for a new object.
The line
Program progis creating a new structure object based on the template defined at the top.So
prog.cm=0;means that yes you are initializing that specific objects cm field to zero.The typedef is there simply so you dont have to write
struct prog 'variableName'when you want to create a new struct object