I like the "pointer magic" approach myself.
For genuinely variable dimensions you might mean both variable length of each dimension and a variable number of dimensions.
"Pointer magic" really isn't so much about pointers or magic, it's just math.
The array subscript syntax is more magic than reality. For example,
1 2 3
|
int a[3][3];
a[2][1] = 0;
|
Here we see the standard 2D array, a 3 x 3 matrix. The location defined by a[2][1] is easily recognized as row 2, column 1 (starting at zero of course).
However, since we know the rows are 3 integers long each, we know that the integer at row 1, column 0 is just after the last column of the previous row. So
1 2 3
|
int a[9];
a[ 2 * 3 + 1 ] = 0;
|
Is effectively identical to the previous example. It is a bit clearer this way:
1 2 3 4 5 6
|
int a[9];
int r = 2;
int c = 1;
a[ r * 3 + c ] = 0;
|
This treats the single dimension array as if it were a 3x3 2D matrix.
So, any block of memory could be used as a multi-dimensional array of any arbitrary organization of rows and columns (and pages, and chapters, etc) at will.
Once you lose the dependency on the convenience of the syntax for 2D or nD arrays from C, it becomes trivial to fashion functions which mutate as required even at runtime.
With a bit of practice and familiarity, the nD syntax of C begins to look cumbersome by comparison.
Nothing drives this home quite as well as when working with images. Uncompressed images tend to look like 2D arrays of color information.
They are rarely ever declared using the 2D array syntax of C, but of strides, like the middle examples I posted where a simple array (or block of RAM) is merely decoded by rows and columns (or x and y coordinates) based on the width of the image.
This continues to echo throughout graphics, where arrays of 3D points are intermixed with data representing normals, and the entire format is handled with strides (the length of each group), which then looks like a 1D array of structures, but the structures are not defined as a class, but by distances from the beginning of each group.