182. C Program to Print Data Using Unions .
How does this program work?
- This Program is used to print integers, float values, characters using unions.
Here is the code
#include <string.h>
//Union declaration
union Data
{
int i;
float f;
char str[20];
};
//By using unions how to print data
int main( )
{
union Data data;
data.i = 660;
printf( "data.i : %d\n", data.i);
data.f = 435.5;
printf( "data.f : %f\n", data.f);
strcpy( data.str, "skillPundit");
printf( "data.str : %s\n", data.str);
return 0;
}