开发者

Array references in two different ways [duplicate]

This question already has answer开发者_StackOverflow中文版s here: Closed 11 years ago.

Possible Duplicate:

In C arrays why is this true? a[5] == 5[a]

int a[5]={1,2,3,4,5};
int i=4;
printf("%d",i[a]);

Why do a[i] and i[a] refer to same location in the array?


This is because array subscript is commutative (it's an addition), the order can be swapped :

a[i] = *(a + i)
i[a] = *(i + a)

*(a + i) = *(i + a)
a[i] = i[a]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜