|
发表于 2022-11-14 10:37:59
|
显示全部楼层
本帖最后由 dolly_yos2 于 2022-11-14 10:47 编辑
好像不是第一次发现需要有回复回复多个帖子的功能了
来看看标准吧(第 6.5.2.1 节,关于 Array subscripting )
1. One of the expressions shall have type "pointer to complete object type", the other expression shall have integer type, and the result has type "type".
2. A postfix expression followed by an expression in square brackets [] is a subscripted designation of an element of an array object. The definition of the subscript operator [] is that E1[E2] is identical to (*((E1)+(E2))). Because of the conversion rules that apply to the binary + operator, if E1 is an array object (equivalently, a pointer to the initial element of an array object) and E2 is an integer, E1[E2] designates the E2 -th element of E1 (counting from zero).
3. Successive subscript operators designate an element of a multidimensional array object. 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. If the unary * operator is applied to this pointer explicitly, or implicitly as a result of subscripting, the result is the referenced (n - 1)-dimensional array, which itself is converted into a pointer if used as other than an lvalue. It follows from this that arrays are stored in row-major order (last subscript varies fastest).
4. EXAMPLE Consider the array object defined by the declaration int x[3][5]; Here x is a 3 × 5 array of int s; more precisely, x is an array of three element objects, each of which is an array of five int s. In the expression x[i], which is equivalent to (*((x)+(i))), x is first converted to a pointer to the initial array of five int s. 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 int s. When used in the expression x[i][j], that array is in turn converted to a pointer to the first of the int s, so x[i][j] yields an int.
水平有限,我先只做搬运,属于是自作多情,两位大佬可以参照
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3047.pdf |
|