Skip to main content

Unions :

Union is a special data type available in c. That allows to store different data types in the same memory location. We can define an union with number of members. But only one member can contain a value at any given time.
And important thing  about union  is we can see with this example that union members share same memory location:


In this example it will print same value as integer it will print 'i' 's ascii value 105 and character value will be 'i' in char value.
In same example if initialize at same time both it will throw warning. After run this program you will get first value 12 but another value it will not print.

Comments