Lesson 22 of 23
Structures (struct)
11 min 35 XP
A struct groups fields of different types into a new type, like a student's name, roll number and marks. typedef gives it a short name, and -> accesses a field through a pointer.
Example: edit me and press Run
Output Loading C (first time takes a few seconds)
Press Run to see the result here.struct vs union: in a union all fields share the same memory. Expect this question in C interviews.