← C Programming learning path
C Programming · Module 8 of 10

Structures

Group related variables of different types with struct.

📖 Key ideas

  1. struct Student { int roll; char name[30]; float marks; }; defines a new type.
  2. Access members with the dot: s.roll.
  3. With a pointer, use the arrow: p->roll.
  4. typedef gives a shorter name: typedef struct Student Student;
  5. Arrays of structs store many records.
💡 Real-life example: A struct is a student ID card: roll number, name and marks together in one card.
structGroups variables into one type
.Accesses a member of a struct variable
->Accesses a member through a pointer
typedefCreates a type alias