As the title suggests, why is this valid and correct?
int main(void)
{
int a[10];
a[5] = 22;
// Prints 22, similar to what a[5] would print.
printf("%d", 5[a]);
}
Three easy steps, converting the array to a pointer:
1.) a[x] == *(a+x)
: An Array operation is the same as a pointer-offset addition
2.) *(a+x) == *(x+a)
: Addition can be reversed
3.) *(x+a) == x[a]
: pointer-offset addition can be converted back to array notation.