C Programming Reference >> C Basic Tutorials >> C Keywords Home >> unionui 30/12/06 - Views - Ratings : The union Keyword is used to defined a user defined varaible whose each member share the same memmory location. Each member of union is defined in code block following the keyword . Name of the union comes in between the union keyword and the opening curly bracket. Name of the objects follows the closing curly bracket. Either name or object are optional but not both. Code - union my
{
int a;
float b;
}o1;
void function (void)
{
union my o2;
o2.a = 10;
o2.b = 0.007;
o1 = o2 ;
printf ("%d %d", o1.a ,o2.a);
printf ("%f %f", o1.b ,o2.b);
}
|