What Is a Struct in C? Explained for Beginners

July 2, 2026 5 min read

C doesn't have built-in support for objects the way languages like Java or Python do, but it gives you something that solves a similar problem: the struct. If you've been writing separate variables for related pieces of data and wondering if there's a better way, structs are the answer.

The Problem Structs Solve

Imagine you're storing information about a student: name, age, and GPA. Without structs, you'd end up with separate, disconnected variables:

char name[50];
int age;
float gpa;

This works for one student, but it falls apart quickly if you need to track multiple students, or pass all of this information to a function together. You'd need three separate arrays or three separate function parameters, and keeping them in sync becomes error-prone.

Defining a Struct

A struct lets you group these related variables into a single custom type:

struct Student {
  char name[50];
  int age;
  float gpa;
};

Now Student is a new type you can use just like int or float. You create a variable of this type like this:

struct Student s1;
s1.age = 20;
s1.gpa = 3.8;

The dot notation (s1.age) lets you access and set individual fields inside the struct.

Why This Matters

Structs make your code dramatically easier to organize once data starts having multiple related fields. Instead of juggling separate variables, you pass a single struct Student to a function and it carries all the related data with it:

void printStudent(struct Student s) {
  printf("%s, age %d, GPA %.1f", s.name, s.age, s.gpa);
}

This keeps related data together conceptually, matching how you'd naturally think about a "student" as one thing with several properties, rather than three unrelated variables that happen to describe the same person.

Structs and Arrays

Structs become even more useful combined with arrays, letting you store a whole list of students:

struct Student classroom[30];

Now you have 30 students, each with their own name, age, and GPA, all organized in a single array you can loop through.

Structs vs Classes

If you've used languages like C++ or Java, structs might remind you of classes, and they're related concepts. The key difference: a plain C struct only holds data, it has no functions attached to it. Classes in object-oriented languages bundle data and behavior together. Structs are essentially a simpler, data-only building block, which fits C's lower-level, close-to-the-hardware philosophy.