-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunion_ex_2.c
34 lines (27 loc) · 935 Bytes
/
union_ex_2.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
33
34
#include <stdio.h>
union student {
char letterGrade;
int roundedGrade;
float exactGrade;
};
int main() {
union student record1;
union student record2;
// assigning values to record1 union variable
record1.letterGrade = 'B';
record1.roundedGrade = 87;
record1.exactGrade = 86.50;
printf("Union record1 values example\n");
printf(" Letter Grade: %c \n\n", record1.letterGrade);
printf(" Rounded Grade: %d \n", record1.roundedGrade);
printf(" Exact Grade: %f \n\n", record1.exactGrade);
// assigning values to record2 union variable
printf("Union record2 values example\n");
record2.letterGrade = 'A';
printf(" Letter Grade: %c \n", record2.letterGrade);
record2.roundedGrade = 100;
printf(" Rounded Grade: %d \n", record2.roundedGrade);
record2.exactGrade = 99.50;
printf(" Exact Grade: %f \n", record2.exactGrade);
return 0;
}