I am sure that this violates at least one rule of the C standard, but it should work in practice. Note that it uses 0 as a control value for the final element of any level of the array.
void print(void* p, int dim) { if (dim == 1) { int* a = (int*) p; while (*a) { printf("%d ", *a++); } printf("\n"); } else { void** a = (void**)p; while (*a) { print(*a++, dim - 1); } } } void test() { int x0 [] = { 11, 12, 13, 14, 15, 0 }; int x1 [] = { 21, 22, 23, 0 }; int x2 [] = { 0 }; int x3 [] = { 41, 42, 0 }; int x4 [] = { 51, 52, 53, 0 }; int* y0 [] = { x0, x3, 0 }; int* y1 [] = { 0 }; int* y2 [] = { x1, x2, x4, 0 }; int** z [] = { y0, y1, y2, 0 }; print(z, 3); }
Print
11 12 13 14 15 41 42 21 22 23 51 52 53
source share