Listing 9 Illustrates a pointer to a 2-d array within a 3-d array
/* array9.c: Uses a pointer to a 2-d array */ #include <stdio.h> main() { int a[][3][4] = {{{0,1,2,3},{4,5,6,7},{8,9,0,1}}, {{2,3,4,5},{6,7,8,9},{0,1,2,3}}}; int (*p)[3][4] = a; int i, j, k; size_t ntables = sizeof a / sizeof a[0]; size_t nrows = sizeof a[0] / sizeof a[0][0]; size_t ncols = sizeof a[0][0] / sizeof a[0][0][0]; printf("sizeof(*p) == %u\n",sizeof(*p)); printf("sizeof(a[0][0]) == %u\n",sizeof(a[0][0])); for (i = 0; i < ntables; ++i) { for (j = 0; j < nrows; ++j) { for (k = 0; k < ncols; ++k) printf("%d ",p[i][j][k]); putchar('\n'); } putchar('\n'); } return 0; } /* Output sizeof(*p) == 24 sizeof(a[0][0]) == 8 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 */ /* End of File */