home *** CD-ROM | disk | FTP | other *** search
- /* array8.c: Uses a pointer to a 1-d array */
-
- #include <stdio.h>
-
- main()
- {
- int a[][4] = {{0,1,2,3},{4,5,6,7},{8,9,0,1}};
- int (*p)[4] = a; /* Pointer to array of 4 ints */
- int i, j;
- size_t nrows = sizeof a / sizeof a[0];
- size_t ncols = sizeof a[0] / sizeof a[0][0];
-
- printf("sizeof(*p) == %u\n",sizeof(*p));
- for (i = 0; i < nrows; ++i)
- {
- for (j = 0; j < ncols; ++j)
- printf("%d ",p[i][j]);
- putchar('\n');
- }
- return 0;
- }
-
- /* Output
- sizeof(*p) == 8
- 0 1 2 3
- 4 5 6 7
- 8 9 0 1
- */
-
-