uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

ptrs_ex2.c (472B)


      1 #include <stdio.h>
      2 
      3 #define ARRLEN(x) (sizeof(x) / sizeof(x[0]))
      4 
      5 /* 
      6  * Make an array and print its contents using both
      7  * indexing and pointer arithemtic
      8  */
      9 
     10 int
     11 main(int argc, char *argv[])
     12 {
     13         int arr[5] = {1, 2, 3, 4, 5};
     14         int i = 0;
     15 
     16         for (; i < ARRLEN(arr); i++) {
     17                 printf("arr[%d]: %d | addr: %p\n", i, arr[i], &arr[i]);
     18                 printf("*(arr + %d): %d | addr: %p\n", i, arr[i], &arr[i]);
     19         }
     20 
     21         return 0;
     22 }