a[n] == n[a]
Page 1 of 1
a[n] == n[a]
- Code:
int main()
{
int a[10] = {1,2,3,4,5,6,7,8,9,10};
if(a[5] == 5[a]) //这里用下标5来做示范,千万不要误会只有5才能这样使用
printf("%d,%d\n",5[a],a[5]);
return 0;
};
6,6
在这段代码里,a[5]和5[a]的作用是一样的(不信你试试看)
因为a[b]的意思是*(a+b),a是地址,b是从a开始接下去的位置
也就是说,*(5+a)和*(a+5)是一样的结果,所以a[5]相等于5[a]
PS: a[5] , 5[a] , *(a+5) , *(5+a) 这4个可以互相代替
too wei- Sponsor
- Posts : 31
Points : 66351
Reputation : 0
Join date : 2015-04-21
Age : 25
Location : Johor
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|