>I was just looking for any pointers, or samples I could look at.
I'll use two dimensional arrays to explain because once you understand them, adding more dimensions is easy. A one dimensional array is easy to figure out, it's a block of items with the same data type running in order:
Code:
int x[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
With the previous declaration, you can easily see how the array is supposed to look, numbers from one to nine in order. A two dimensional array is an array of arrays:
Code:
int x[4][9] =
{
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
};
By carefully writing the declaration you can show how a two dimensional array looks as well. There are 4 arrays with 9 elements as opposed to the first declaration which was one array with 9 elements. To access one of the elements in a two dimensional array you simply give a subscript for which array to use, and then another subscript for which element of that array:
The value variable would now hold the item contained in the third element of the fourth array, note that array indexes start at zero. That's what a two dimensional array is, and it is used in a similar manner as a one dimensional array with added code to handle both levels. A common practice is to use nested loops to populate a 2D array:
Code:
int i, j;
for ( i = 0; i < 4; i++ )
for ( j = 0; j < 9; j++ )
x[i][j] = j + 1;
Whereas a 1D array would only require a single loop. Note that a 2D array can also be populated by a single loop, but the syntax is less intuitive:
Code:
int i, *p;
for ( i = 0, p = &x[0][0]; i < 4 * 9; i++ )
*p++ = i + 1;
With this knowledge in hand, multidimensional arrays are easy, simply add another array:
This is an array of four arrays of two arrays. Each element of the first dimension is an array of nine elements where each of those elements is an array of two elements. The usage is very similar to a 2D array except for extra code to handle the new dimension. You can continue adding dimensions this way without getting confused. In case you were wondering, the most dimensions I've ever used is 8. I tried more but got a stack overflow with 9 or more.
-Prelude