fork download
  1. #include <stdio.h>
  2.  
  3. struct X { int a, b, c; };
  4.  
  5. int main(void) {
  6. struct X x = {.a=1, .b=2};
  7. printf("x: %d %d %d\n", x.a, x.b, x.c);
  8. x = (struct X){.a=1, .c=3};
  9. printf("x: %d %d %d\n", x.a, x.b, x.c);
  10. // initialize a const
  11. // order can be changed when elements are named
  12. const struct X cx = {.c=3, .b=2, .a=1};
  13. printf("cx: %d %d %d\n", cx.a, cx.b, cx.c);
  14. // cast the const away
  15. ((struct X*)(&cx))->a = 0;
  16. printf("cx: %d %d %d\n", cx.a, cx.b, cx.c);
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
x: 1 2 0
x: 1 0 3
cx: 1 2 3
cx: 0 2 3