MultiDimensional Arrays


C allows arrays of more than two dimensions. Two exact limits, if any, is determined by your compiler. The simple form of a multidimensional array declaration is

type name[Size1][Size2][Size3]....[SizeN];

Arrays of more than three dimensions are often used because of the amount of memory they require. For example, a four-dimensional character array with dimensions 10,8,7,9 requires

or 5040 bytes. If the array held 2-byte integers, 10080 bytes would be needed. If the array held doubles, 40320 bytes would be required. The storage required increases exponentially with the number of dimensions.

It takes computer time to calculate each index in multidimensional arrays. This means that accessing an element in a multidimensional array can be slower than accessing an element in a single-dimensional array.

When transferring multidimensional arrays to a function, you must declare all except the dimensions on the left. For example, if you declare an array as a number, declare

int numbers[4][6][7][8];

a function, func(), that receives numbers, would look like this :

void func(int a[][4][5][6])
{
 .....
}