-
Notifications
You must be signed in to change notification settings - Fork 2
/
Union.c
32 lines (28 loc) · 832 Bytes
/
Union.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// author: jaydattpatel
#include <stdio.h>
#include <string.h>
//union can store only one data at a time of its elements and length of union will be same of its bigest size of member. Here union length id 20 bytes because variable c[20] is biggest element.
union Data
{
int a;
float b;
char c[20];
};
int main( )
{
union Data table;
printf( "Memory size occupied by data : %d\n", sizeof(table));
table.a = 10;
table.b = 220.5;
strcpy( table.c, "C Programming");
printf( "table.a : %d\n", table.a);
printf( "table.b : %f\n", table.b);
printf( "table.c : %s\n\n", table.c);
table.a = 10;
printf( "table.a : %d\n", table.a);
table.b = 220.5;
printf( "table.b : %f\n", table.b);
strcpy( table.c, "C Programming");
printf( "table.c : %s\n", table.c);
return 0;
}