Struct Padding in C: Overview, Examples, Visuals

Kyra Krishna
mycsdegree
Published in
7 min readFeb 16, 2023

--

A screenshot of a C file. It contains the struct “student” with a string (char *) name, int age, double gpa and char or boolean to represent “is a cs major”.
Courtesy of Kyra Krishna. A picture of the struct “student” with a string (char *) name, int age, double gpa, and char or boolean to represent “is a cs major”.

A struct in C is a composite data type that allows you to group multiple variables together and store them in the same block of memory. If you’re familiar with Java, they’re a little similar to class definitions. In the picture above, a struct is being used to represent a “student” type, that has a name, age, gpa, and is_cs_major boolean value associated with if they are a cs major. Also note that the…

--

--

Kyra Krishna
mycsdegree

A computer science student with too many interests and just enough time to try them all.