Why `5[a]` Can Work in C

C defines a subscript in terms of pointer arithmetic: `a[5]` means `((a) + 5)`. Here, `a` supplies a pointer to an element, and adding 5 moves that pointer five elements forward—not five bytes. The `` then reads the value at the resulting address.

C also allows an integer to be added to a pointer in the opposite order. Since `5 + a` reaches the same address as `a + 5`, `5[a]` means `*((5) + a)`, which reaches the same element as `a[5]`.

A Language Rule, Not a Different Kind of Indexing

This works because C specifies subscripting through pointer addition; the brackets do not require the pointer to appear first. In an expression such as `a[5]`, an array name is converted to a pointer to its first element, enabling that arithmetic.

The reversed form has the same bounds requirements as ordinary indexing. The resulting pointer must refer to an element of the array for it to be dereferenced safely. Although `5[a]` is valid when those conditions hold, it is rarely used in ordinary code: `a[5]` makes the intended relationship between an array and its index immediately clear.