Ch 12 · Structures · C
Topic 12 of 13 in C — Complete Tutorial (Beginner) — 2 lessons.
Defining and Using a struct
A structure (struct) groups several related variables of different types under one name — C's way of modelling a real-world "thing" like a student or a point. You define the structure once with its fields, then create variables of that type and access each field with a dot. Structures let you treat related data as a single unit instead of juggling many separate variables.
Arrays of Structures
The real power shows when you store many structures in an array — a whole class of students, a list of products. You loop over the array and use the dot operator on each element to reach its fields. This combination — an array of structs plus a loop — models almost any real-world dataset, and is one of the most common patterns in C programs.