I saw such a piece of C code:
int main()
{
static int a[] = {7,8,9};
printf("%d", 2[a] + a[2]);;
return 0;
}
What does 2[a]
mean here?
a[b]
and b[a]
are 100% equivalent in C. What you have there is a very unidiomatic way of writing a[2]
.
By way of more complete explanation, array subscript notation a[b]
is also 100% equivalent to *(a + b)
, which may make the reason it works both ways clearer.