1 /* G04E06 - Print elements of a 2D array using a pointer 2 * by Martin J. Kloeckner 3 * github.com/klewer-martin */ 4 5 #include <stdio.h> 6 7 int main (void) 8 { 9 int *dos_ptr; 10 int (*ptr2vector)[4]; 11 12 int dos_vector[3][4] = {{ 1, 2, 3, 4 }, 13 { 5, 6, 7, 8 }, 14 { 9,10,11,12 }}; 15 16 dos_ptr = dos_vector[0]; 17 for(size_t i = 0; i < 3 * 4; i++) 18 printf("dos_vector[%ld][%ld]: %2d\n", i / 4, i % 4, *(dos_ptr + i)); 19 20 putchar(10); 21 ptr2vector = dos_vector; 22 for(size_t i = 0; i < 3; i++) { 23 for(size_t j = 0; j < 4; j++) 24 printf("%2d ", *(ptr2vector[i] + j)); 25 26 putchar(10); 27 } 28 29 return 0; 30 }