How to use Union in C language
I have a question about union in C Language. The variables declared in a union will share the same memory, ok, I understand. for example, union student { int i; int j; }x; how could we access the i and j? if we have: x.i = 1; and then we printf("%d",j); what will happen? compiler error? Ok then what about the following case: union student { int i; float j; }x; if we assign x.i = 2; what is the value of x.j? Assuming you use printf("%d", x.j); You will see the same value you assigned to x.i , since both variables occupy the same area of memory. It would not be typical to make both variables of