Check the following C code I wrote. I thought the compiler may complain about i[a], but it actually prints the exact same value as a[i]. How does this happen?
#include <stdio.h>
int main(){
int a[3] = {0, 1, 2};
int i;
for(i = 0; i < 3; i++){
printf("normal a[%d] = %d\n", i, a[i]);
printf("abnormal a[%d] = %d\n", i, i[a]);
}
return 0;
}
The print out values:
normal a[0] = 0
abnormal a[0] = 0
normal a[1] = 1
abnormal a[1] = 1
normal a[2] = 2
abnormal a[2] = 2