It is because of pointer arithmetic:
a[1] == *(a+1) == *(1+a) == 1[a];
Quoting the standard (§8.3.4; point 6):
Except where it has been declared for a class, the subscript operator []
is interpreted in such a way that E1[E2]
is identical to *((E1)+(E2))
. Because of the conversion rules that apply to +
, if E1
is an array and E2
an integer, then E1[E2]
refers to the E2
-th member of E1
. Therefore, despite its asymmetric appearance, subscripting is a commutative operation.
Note that when you write a[1]
, the compiler interprets it as *(a+1)
. You are still referring the same array a
when you write 1[a]
, so the compiler is infact still doing type checking.