Evo. G Tech Team Forum
Welcome to Evo. G Tech Team Forum. We have moved to a new website : www.evogtechteam.com

Thanks you.

by Evo. G Tech Team Management.

a[n] == n[a]

View previous topic View next topic Go down

a[n] == n[a]

Post by too wei on August 1st 2015, 00:53

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
Sponsor

Posts : 31
Points : 17811
Reputation : 0
Join date : 2015-04-21
Age : 19
Location : Johor

View user profile

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum