Search⌘ K

Introduction to a Union

Explore the concept of unions in C programming to understand how they allocate memory equal to their largest member. Learn to declare and use unions to efficiently group dissimilar data types while conserving memory space.

All secondary types are built out of primary data types. Of these, this chapter discusses the data type called Union.

What is a union?

The purpose of both a union and a structure is to group dissimilar items together. But the key difference is that a structure allocates enough memory to store all of its members in memory. Whereas, a union allocates memory equal to the size of ...