Union : Union « Data Type « C Tutorial






  1. Union has members of different data types, but can hold data of only one member at a time.
  2. The different members share the same memory location.
  3. 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








2.26.Union
2.26.1.Union
2.26.2.Output both value in a union