Skip to main content

Structure vs Union in C

Both struct and union are user-defined data types in C that group multiple members together. They differ fundamentally in how memory is allocated and how members are accessed.

Comparison Table


Memory Illustration


Example: Side by Side

Output:

Enum in C

An enum (Enumeration) is a user-defined type that assigns meaningful names to integer constants. It makes code more readable.
By default, the first constant = 0, and each subsequent one increments by 1. Custom values:
Complete example: