C program to illustrate the concept of unions

by Nideesh C on April 13, 2011 · 0 comments

in C Programming




/* C program to illustrate the concept of unions */

#include <stdio.h>
#include <conio.h>

void main()
{
union number
{
int  n1;
float n2;
};

union number x;

clrscr() ;

printf(“Enter the value of n1: “);
scanf(“%d”, &x.n1);
printf(“Value of n1 =%d”, x.n1);

printf(“\nEnter the value of n2: “);
scanf(“%d”, &x.n2);
printf(“Value of n2 = %d\n”,x.n2);

}     /* End of main() */

/*————————————
Output
Enter the value of n1: 2
Value of n1 =2
Enter the value of n2: 3
Value of n2 = 0
————————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to input real numbers and find the mean, variance and standard deviation
  2. C program to check whether a given integer number is positive or negative
  3. C program to accept a set of numbers and compute mean, variance and standard deviation
  4. C program to accept an array of 10 elements and swap 3rd element with 4th element using pointers. And display the results
  5. C program to read two integers M and N and to swap their values. Use a user-defined function for swapping. Output the values of M and N before and after swapping with suitable messages

Leave a Comment

Previous post:

Next post: