A struct bundles related values into one named record; a union lets several members share the same bytes.
1 One box, many types
A struct groups values of different types — name, score, health — under a single variable name.
2 Members live side by side
Each struct member gets its own memory; changing one never touches the others.
3 Dot and arrow
Use p.score for a struct variable, and p->score when p is a pointer to a struct.
4 Union = shared memory
A union keeps all members at one address — writing one member overwrites the others.
One name, many values
One box, many types1A struct groups values of different types — name, score, health — under a single variable name. Members live side by side2Each struct member gets its own memory; changing one never touches the others. Dot and arrow3Use p.score for a struct variable, and p->score when p is a pointer to a struct. Union = shared memory4A union keeps all members at one address — writing one member overwrites the others. 4 building blocks make up One name, many values
The choice is about memory: keep everything together, or reuse one block for different views.
process decision input / output start / end Tabs switch programs — watch struct members update independently, then watch a union overwrite itself.
preprocessThe preprocessor pastes in stdio.h — printf comes from there.
Memory
no variables yet — press play
Console
output appears as the program runs…
Click a term, then click its meaning to lock the pair.
5 conceptsTap a card to expand ?structdrops into place
?uniondrops into place
?p.scoredrops into place
?p->scoredrops into place
?struct Player pdrops into place
Two members, two updates — one depends on the other.
Your predicted output — one line per console line
Hint: Members update in order — p.y reads the NEW value of p.x because p.x changed first.
01A struct is a record: members keep separate memory and can change independently.
02A union is one shared block — only the most recently written member makes sense.
03Unions save memory when you need one of several views, never all at once.
04Use . for struct variables and -> for pointers to structs.
05Initialize structs with { ... } lists — members fill in order.