Back to Blog

C in 100 Seconds: Structs | Episode 23

Daryl WongDaryl Wong

Video: C in 100 Seconds: Structs | Episode 23 by Taught by Celeste AI - AI Coding Coach

Watch full page →

Structs in C — Group Your Data

C in 100 Seconds, Episode 23


Variables are great for single values. But what happens when you need to represent something with multiple properties — like a student with a name, an age, and a GPA? That is where structs come in.

What Is a Struct?

A struct is a custom type that groups different types together under one name. Instead of managing three separate variables, you get one unit.

lets you use directly as a type name. Without it, you would have to write every time.

Creating and Initializing

Initialize with curly braces — values go in the same order as the members were defined:

Alice for name, 20 for age, 3.85 for GPA. One line, one variable, all three values.

Accessing Members

Use the dot operator to read any field:

Modifying Members

Structs are mutable. Assign to any field to change it:

The other fields stay the same. You are only changing what you target.

Why Structs Matter

Structs are the building block of organized data in C:

  • Data modeling — represent real-world objects (students, points, records)
  • Function parameters — pass a single struct instead of five separate arguments
  • Arrays of structs — a list of students, a deck of cards, a table of records
  • Pointer to struct — the arrow operator unlocks dynamic data structures

Without structs, C programs would be a mess of unrelated variables. With them, your data has shape.

Full Code

Compile and run:


Next episode: Structs and Pointers — the arrow operator and heap-allocated structs.

Student code: github.com/GoCelesteAI/c-in-100-seconds/episode23