1

Possible Duplicate:
In C arrays why is this true? a[5] == 5[a]

int a[5]={1,2,3,4,5};
int i=4;
printf("%d",i[a]);

Why do a[i] and i[a] refer to same location in the array?

Community
  • 1
  • 1
jemmanuel
  • 466
  • 4
  • 13

1 Answers1

2

This is because array subscript is commutative (it's an addition), the order can be swapped :

a[i] = *(a + i)
i[a] = *(i + a)

*(a + i) = *(i + a)
a[i] = i[a]
user703016
  • 37,307
  • 8
  • 87
  • 112