Struct vs Union

Onur Uzun
1 min readMay 8, 2020

A structure is a user-defined data type available in C that allows to combining data items of different kinds.

A union is a special data type available in C that allows storing different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multiple purposes.

The purpose of union is to save memory by using the same memory region for storing different objects at different times.

struct [structure name]
{
member definition;
member definition;
...
member definition;
};
union [union name]
{
member definition;
member definition;
...
member definition;
};

--

--