• 博客访问： 7377549
• 博文数量： 159
• 博客积分： 10424
• 博客等级： 少将
• 技术积分： 14605
• 用 户 组： 普通用户
• 注册时间： 2010-07-14 12:45

2015年（5）

2014年（1）

2013年（5）

2012年（10）

2011年（116）

2010年（22）

2011-10-09 23:06:19

A postﬁx expression followed by an expression in square brackets [] is a subscripted
designation of an element of an array object. The deﬁnition 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).

The unary & operator yields the address of its operand. If the operand has type "type", the result has type "pointer to type". If the operand is the result of a unary * operator, neither that operator nor the & operator is evaluated and the result is as if both were omitted, except that the constraint on the operators still apply and the result is not an lvalue. Similarly, if the operand is the result of a [] operator, neither the & operator nor the unary * that is implied by the [] is evalued and the result is as if & operator were removed and the [] operator were changed to a + operator. Otherwise, the result is a pointer to the object or function designated by its operand.

1. #include <stdlib.h>
2. #include <stdio.h>

3. int main()
4. {
5.     int *p = NULL;
6.     int array[10] = {1,2,3,4,5,6,7,8,9,0};

7.     printf("p is %p and value is %d\n", &*p, 2[array]);

8.     return 0;
9. }

1. p is (nil) and value is 3

GFree_Wind2011-10-11 18:01:44

haotianmai: expert c中有句原话：
B simplified BCPL by omitting some features (such as nested procedures and some loop-ing constructs) and carried forward the ide.....

haotianmai2011-10-11 15:32:46

expert c中有句原话：
B simplified BCPL by omitting some features (such as nested procedures and some loop-ing constructs) and carried forward the idea that array references should "decompose" into pointer-plus-offset references.

haotianmai2011-10-11 14:37:45

E1[E2]其实编译器是按*(E1+E2)处理的。