Thursday, 20 March 2014

PROGRAM IN C TO SHOW THE USE OF UNION

/*…Hey guy’s this is a program to show how the union is used in programs…*/
#include <stdio.h>
union number
{
int x;
double y;
};
/*..Main Function Start’s…*/
void main()
{
/*…Initialization And Declaration…*/
union number value;
value.x = 100;
printf( “%s\n%s\n%s%d\n%s%f\n\n”,“Put a value in the integer member”,“and print both members.”,“int: “, value.x,
“double:\n”, value.y );
value.y = 100.0;
printf( “%s\n%s\n%s%d\n%s%f\n”,
“Put a value in the floating member”,
“and print both members.”,
“int: “, value.x, 
“double:\n”, value.y );
getch();
}
/*…Main Function End’s…*/
the output is
Image

No comments:

Post a Comment