[dcl.array] (original) (raw)

When several “array of” specifications are adjacent, a multidimensional array type is created; only the first of the constant expressions that specify the bounds of the arrays can be omitted.

[Example 4:

int x3d[3][5][7];declares an array of three elements, each of which is an array of five elements, each of which is an array of seven integers.

The overall array can be viewed as a three-dimensional array of integers, with rank 3 ×5 ×7.

Any of the expressionsx3d,x3d[i],x3d[i][j],x3d[i][j][k]can reasonably appear in an expression.

The expressionx3d[i]is equivalent to*(x3d + i); in that expression,x3dis subject to the array-to-pointer conversion ([conv.array]) and is first converted to a pointer to a 2-dimensional array with rank5 ×7that points to the first element of x3d.

Then i is added, which on typical implementations involves multiplyingi by the length of the object to which the pointer points, which is sizeof(int)×5 ×7.

The result of the addition and indirection is an lvalue denoting the array element ofx3d(an array of five arrays of seven integers).

If there is another subscript, the same argument applies again, sox3d[i][j] is an lvalue denoting the array element of the array element ofx3d(an array of seven integers), andx3d[i][j][k] is an lvalue denoting the array element of the array element of the array element ofx3d(an integer).

— _end example_]

The first subscript in the declaration helps determine the amount of storage consumed by an array but plays no other part in subscript calculations.