C Language

What is Union in C

In C Language by Baqir AliLeave a Comment

Union is similar to structure in that both have several members but a union can hold value in only one of its members at any time. Members are overlaid in the storage allocation for a union variable. The compiler allocates sufficient storage to accommodate the largest member of a union.

union num
{
	char character;
	short short_int;
	float floating;
} data;
Union in C
  • Just like struct, we use the . operator to access members of a union variable.
  • It’s the programmer’s responsibility to keep track of what data type is currently stored in a union variable.

Leave a Comment