#include <stdio.h>
main()
{
char a[5] = "abcd";
int b = 3;
printf("%c
",a[b]);
printf("%c
",((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/