Guest User

Untitled

a guest
Dec 15th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. /* a.c - defines an array */
  2.  
  3. int a[] = {1,2,3,4,5,6,7,8,9};
  4.  
  5.  
  6. /* b.c - declare and use it. */
  7.  
  8. #define COUNT ((sizeof a)/(sizeof int))
  9. extern int a[]; //size of array
  10.  
  11. .
  12. .
  13. .
  14.  
  15. int i;
  16. for(i=0; i<COUNT; i++)
  17. printf("%d", a[i]);
  18. .
  19. .
  20. .
  21.  
  22. int a[] = {1, 2, 3};
  23. const int lengthofa = sizeof( a ) / sizeof( a[0] );
  24.  
  25. extern int a[];
  26. // the extern (thanks Tim Post) declaration means the actual storage is in another
  27. // module and fixed up at link time. The const (thanks Jens Gustedt) prevents it
  28. // from being modified at runtime (and thus rendering it incorrect).
  29. extern const int lengthofa;
  30.  
  31. void somefunc() {
  32. int i;
  33. for ( i = 0; i < lengthofa; i++ )
  34. printf( "%dn", a[i] );
  35. }
  36.  
  37. extern int a[9];
  38.  
  39. #ifndef A_DEF
  40. #define A_DEF
  41. int a[] = {1,2,3,4,5,6,7,8,9};
  42. #endif
Add Comment
Please, Sign In to add comment