Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-std=c99
- #include <stdio.h>
- #include <stdlib.h>
- int main (int argc, char **argv)
- {
- typedef struct s1 {
- float fV1;
- float fV2;
- } s1;
- typedef struct s2 {
- float fV1;
- char cV2;
- } s2;
- typedef union u1 {
- s1 m1;
- s2 m2;
- } u1;
- union u1 nu1 = {{0.1f,0.2f}};
- printf("nu1 (0): %f\n",nu1.m1.fV1);
- printf("nu1 (1): %f\n\n",nu1.m1.fV2);
- //designated union initializer
- union u1 nu2 = {.m2.fV1 = 0.3f, .m2.cV2='C'};
- printf("nu2 (0): %f\n",nu2.m2.fV1);
- printf("nu2 (1): %c\n\n",nu2.m2.cV2);
- union u1 nu3;
- nu3.m2.fV1 = 0.5f;
- nu3.m2.cV2 = 'c';
- printf("nu3 (0): %f\n",nu3.m2.fV1);
- printf("nu3 (1): %c\n\n",nu3.m2.cV2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment