Unions and Memory Efficiency
Understand the differences between struct and union and how unions optimize memory usage.
1
Unions and Memory Efficiency
A union is a special data type that allows storing different data types in the same memory location.
In this lesson, you will learn:
- How to define and use unions.
- The difference between structures and unions.
- How unions optimize memory usage.

2
What is a Union?
A union is similar to a structure, but all members share the same memory space.
Example:
union Data {
int i;
float f;
char str[20];
};
Here, i, f, and str share the same memory location.
All lessons in this course
- Defining and Using Structures
- Unions and Memory Efficiency
- Enumerations (enum)