Possible Duplicate:
In C arrays why is this true? a[5] == 5[a]
Can anyone explain me why for any array the expression c a[7] == 7[a] is true.
is there any case that it can be false
I have seen in wiki that x[i] is a syntactic sugar for *(x+i) and this is equal to *(i+x) and this is i[x], but I can not understand this properly.
a[7]is equivalent to*(a + 7).7[a]is equivalent to*(7 + a).This gives the same result because adding an integer to a pointer is a commutative operation.
The short answer is no. For simple pointer arithmetic it will always be true.
The long answer is that to find a counterexample you would have to use a hack. One way you could do it is to use a macro:
Result:
The result is different because after the macro expansion the expressions become different:
1+(s[7])versus7[1+s].See it online: ideone