Advertisement
teknoraver

static array initialize

Sep 11th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.32 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.     int i;
  6.     int v[10] = { [0 ... 3] = 2, [4 ... 8] = 4, [9] = 6 };
  7.  
  8.     for(i = 0; i < sizeof(v) / sizeof(*v); i++)
  9.         printf("v[%d]: %d\n", i, v[i]);
  10.  
  11.     return 0;
  12. }
  13.  
  14. /*
  15.  
  16. v[0]: 2
  17. v[1]: 2
  18. v[2]: 2
  19. v[3]: 2
  20. v[4]: 4
  21. v[5]: 4
  22. v[6]: 4
  23. v[7]: 4
  24. v[8]: 4
  25. v[9]: 6
  26.  
  27. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement