a[b]和b[a]区别

#include <stdio.h>
main()
{
char a[5] = "abcd";
int b = 3;

printf("%c\n",a[b]);
printf("%c\n",((char *) b)[(int) a]);
}

结果:

d

d

分析:pointer[offset] is just worked out as pointer+offset*sizeof(*pointer) so there's no difference between a[b] and b[a], providing b and a in the latter case are cast correctly.

摘自:http://www.go4expert.com/forums/ia-ai-related-t29312/

posted @ 2013-10-01 10:02  wdliming  阅读(133)  评论(0编辑  收藏  举报