Union in C.

 

01  #include<stdio.h>
02
03 union My
04 {
05 int x;
06 float y;
07 char z;
08 }u;
09
10
11 int main()
12 {
13 u.x=10;
14 printf("x = %d n",u.x);
15
16 u.y=9.8;
17 printf("y = %f n",u.y);
18
19 u.z='a';
20 printf("z = %c n",u.z);
21
22 return 0;
23 }
 
OUTPUT 
x = 10
y = 9.800000
z = a

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *