fork download
  1. #include <stdio.h>
  2.  
  3. union my_union
  4. {
  5. int a;
  6. struct {
  7. char b1;
  8. char b2;
  9. char b3;
  10. char b4;
  11. } b;
  12. };
  13.  
  14. int main()
  15. {
  16. union my_union x;
  17.  
  18. x.a = 1000;
  19.  
  20. printf("x.a = %d\n", x.a);
  21. printf("x.b.b1 = %d\n", x.b.b1);
  22. printf("x.b.b2 = %d\n", x.b.b2);
  23. printf("x.b.b3 = %d\n", x.b.b3);
  24. printf("x.b.b4 = %d\n", x.b.b4);
  25.  
  26. printf("%ld\n", sizeof(union my_union));
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
x.a = 1000
x.b.b1 = -24
x.b.b2 = 3
x.b.b3 = 0
x.b.b4 = 0
4