fork download
  1. #include <ctype.h>
  2. #include <stddef.h>
  3. #include <stdio.h>
  4.  
  5. int main(void)
  6. {
  7. char ca[10] = {[4] = 'e', [0] = 'a', [2] = 'c', [1] = 'b', [3] = 'd', [9] = 'z'};
  8.  
  9. // 0 1 2 3 4 . . . . . . 9
  10. // ca == {'a', 'b', 'c', 'd', 'e', 0, 0, 0, 0, 'z'}
  11.  
  12. printf("Contents of ca:\n ");
  13.  
  14. // the zeros are not printable, because they aren't the '0' character,
  15. // so we need to cast them to int so as to print their numeric value
  16. for (size_t i=0; i < sizeof ca; ++i)
  17. if (isprint(ca[i]))
  18. printf("%c ", ca[i]);
  19. else
  20. printf("%d ", (int)ca[i]);
  21.  
  22. printf("\n\n");
  23.  
  24. struct Test
  25. {
  26. char c;
  27. int i;
  28. float f;
  29. };
  30.  
  31. struct Test t = {/*.f = 3.14f,*/ .c = 'Z', .i = 10}; // <==>struct Test t = { 3.14f, 'Z' , };
  32.  
  33. printf("Contents of t:\n c == %c\n i == %d\n f == %f\n", t.c, t.i, t.f);
  34. }
  35.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
Contents of ca:
  a b c d e 0 0 0 0 z 

Contents of t:
  c == Z
  i == 10
  f == 0.000000