union [union tag]
{
member definition;
member definition;
...
member definition;
} [one or more union variables];
union Data
{
int i;
float f;
char str[20];
} data;
#include <stdio.h>
#include <string.h>
union Data
{
int i;
float f;
char str[20];
};
int main( )
{
union Data data;
printf( "Memory size occupied by data : %d
", sizeof(data));
return 0;
}
#include <stdio.h>
#include <string.h>
union Data
{
int i;
float f;
char str[20];
};
int main( )
{
union Data data;
data.i = 10;
data.f = 220.5;
strcpy( data.str, "C Programming");
printf( "data.i : %d
", data.i);
printf( "data.f : %f
", data.f);
printf( "data.str : %s
", data.str);
return 0;
}
#include <stdio.h>
#include <string.h>
union Data
{
int i;
float f;
char str[20];
};
int main( )
{
union Data data;
data.i = 10;
printf( "data.i : %d
", data.i);
data.f = 220.5;
printf( "data.f : %f
", data.f);
strcpy( data.str, "C Programming");
printf( "data.str : %s
", data.str);
return 0;
}