Array subscripting

Previous Table of Contents "New C Standard" commentary

987 One of the expressions shall have type “pointer to object type”, the other expression shall have integer type, and the result has type “type”.

988 A postfix expression followed by an expression in square brackets [] is a subscripted designation of an element of an array object.

989 The definition of the subscript operator [] is that E1[E2] is identical to (*((E1)+(E2))).


991 Successive subscript operators designate an element of a multidimensional array object.

992 If E is an n-dimensional array (n≥2) with dimensions i × j × ... × k then E (used as other than an lvalue) is converted to a pointer to an (n−1)-dimensional array with dimensions j × ... × k

993 If the unary * operator is applied to this pointer explicitly, or implicitly as a result of subscripting, the result is the pointed-to (n - 1)-dimensional array, which itself is converted into a pointer if used as other than an lvalue.

994 It follows from this that arrays are stored in row-major order (last subscript varies fastest).

995 EXAMPLE Consider the array object defined by the declaration

        int x[3][5];

Here x is a 3 × 5 array of ints; more precisely, x is an array of three element objects, each of which is an array of five ints. In the expression x[i], which is equivalent to (*((x)+(i))), x is first converted to a pointer to the initial array of five ints. Then i is adjusted according to the type of x, which conceptually entails multiplying i by the size of the object to which the pointer points, namely an array of five int objects. The results are added and indirection is applied to yield an array of five ints. When used in the expression x[i][j], that array is in turn converted to a pointer to the first of the ints, so x[i][j] yields an int.

996 Forward references: additive operators (6.5.6), address and indirection operators (, array declarators (


Created at: 2008-01-30 02:39:42 The text from WG14/N1256 is copyright © ISO