-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_06.c
29 lines (22 loc) · 777 Bytes
/
Day_06.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
#include <stdio.h>
/*This is the project for testing my learning in Memory alloction for Union in C. It initializes a variable for each member and allocate memory implicitly for all members of the Union*/
union myUnion
{
int integer;
char charArray[10];
float float_number;
};
int main(void)
{
union myUnion example; /*This will automatocally/implicitly allocate memory for Union 'myUnion'*/
/* Initializes Integer data type */
example.integer = 42;
printf("Integer: %d\n", example.integer);
/* Initializes charArray data type */
strcpy(example.charArray, "Sobil");
printf("Char Array: %s\n", example.charArray);
/* Initializes float data type */
example.float_number = 3.14;
printf("Float Numberr: %.2f\n", example.float_number);
return 0;
}