but there is no such thing as a 2D array in C++ |
|
|
f 6 |
|
|
In a declaration T D where D has the form D1 [ constant-expression opt ] ... ... then the type of the identifier of D is an array type; When several “array of” specifications are adjacent, a multidimensional array is created ... [Example: ... static int x3d[3][5][7]; declares a static three-dimensional array of integers, with rank 3×5×7. In complete detail, x3d is an array of three items; each item is an array of five arrays; each of the latter arrays is an array of seven integers. Any of the expressions x3d, x3d[i], x3d[i][j], x3d[i][j][k] can reasonably appear in an expression. ... —end example] ... A consistent rule is followed for multidimensional arrays. If E is an n-dimensional array of rank i×j×...×k, then E appearing in an expression that is subject to the array-to-pointer conversion is converted to a pointer to an (n−1)-dimensional array with rank j×...×k. ... ... [Example: consider int x[3][5]; Here x is a 3 × 5 array of integers. When x appears in an expression, it is converted to a pointer to (the first of three) five-membered arrays of integers. ... —end example ] ... [Note: It follows from all this that arrays in C ++ are stored row-wise (last subscript varies fastest) and that the first subscript in the declaration helps determine the amount of storage consumed by an array but plays no other part in subscript calculations. —end note ] ... template <class T> struct rank; If T names an array type, an integer value representing the number of dimensions of T; otherwise, 0. |