#include <stdio.h>
int main()
{
char a[] = {'a', 'b', 'c'};
int b = 1;
printf("--%c--\n", a[b]);
printf("--%c--\n", b[a]);
printf("--%c--\n", 1[a]);
return 0;
}
All three print the same --b--
.
Why? The direct access would be using pointer *(a + b)
and there the plus sign is commutative. The bracket notation is just syntactic sugar and apparently it does not check for the weird swapped notation.