Union has members of different data types, but can hold data of only one member at a time.
The different members share the same memory location.
The total memory allocated to the union is equal to the maximum size of the member.
#include <stdio.h>
union marks
{ float percent; char grade;
}; int main ( )
{
union marks student1;
student1.percent = 98.5;
printf( "Marks are %f address is %16lu\n", student1.percent, &student1.percent);
student1.grade = 'A';
printf( "Grade is %c address is %16lu\n", student1.grade, &student1.grade);
}
Marks are 98.500000 address is 2293620
Grade is A address is 2293620