home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_09 / 1109117a < prev    next >
Text File  |  1993-07-13  |  878b  |  43 lines

  1. /* array9.c:    Uses a pointer to a 2-d array */
  2.  
  3. #include <stdio.h>
  4.  
  5. main()
  6. {
  7.     int a[][3][4] = {{{0,1,2,3},{4,5,6,7},{8,9,0,1}},
  8.                      {{2,3,4,5},{6,7,8,9},{0,1,2,3}}};
  9.     int (*p)[3][4] = a;
  10.     int i, j, k;
  11.     size_t ntables = sizeof a / sizeof a[0];
  12.     size_t nrows   = sizeof a[0] / sizeof a[0][0];
  13.     size_t ncols   = sizeof a[0][0] / sizeof a[0][0][0];
  14.  
  15.     printf("sizeof(*p) == %u\n",sizeof(*p));
  16.     printf("sizeof(a[0][0]) == %u\n",sizeof(a[0][0]));
  17.     for (i = 0; i < ntables; ++i)
  18.     {
  19.         for (j = 0; j < nrows; ++j)
  20.         {
  21.             for (k = 0; k < ncols; ++k)
  22.                 printf("%d ",p[i][j][k]);
  23.             putchar('\n');
  24.         }
  25.         putchar('\n');
  26.     }
  27.     return 0;
  28. }
  29.  
  30. /* Output
  31. sizeof(*p) == 24
  32. sizeof(a[0][0]) == 8
  33. 0 1 2 3
  34. 4 5 6 7
  35. 8 9 0 1
  36.  
  37. 2 3 4 5
  38. 6 7 8 9
  39. 0 1 2 3
  40.  
  41. */
  42.  
  43.