This is a C program to illustrate the concept of unions.
This program illustrates the concept of unions.
1. Define the union.
2. Take the input and store it in the variable using dot operator.
3. Print the output using dot operator and exit.
Here is source code of the C program to illustrate the concept of unions. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to illustrate the concept of unions
union number x;
printf("Enter the value of n1: ");
printf("Value of n1 = %d", x.n1);
printf("\nEnter the value of n2: ");
printf("Value of n2 = %f\n", x.n2);
1. Define the union named number with two variables n1 and n2.
2. Define the union variable x.
3. Take the value of two variables using dot operator(i.e. x.n1, x.n2) as input.
4. Print the values of two variables using dot operator as output.
Enter the value of n1: 10 Value of n1 = 10 Enter the value of n2: 50 Value of n2 = 50.000000
Sanfoundry Global Education & Learning Series – 1000 C Programs.