John Gateley

Fun with C/C++ Arrays


Consider the following code fragment:
char *s="abcde";
printf("%c", 2[s]);
What does this print in C? in C++?

Once you think you understand, consider this:

s[2] = *(s+2*sizeof(*s))
2[s] = *(2+s*sizeof(*2))
What is sizeof(*2)?