-1

What makes this construction?

int a[10];
int x;
x = 2[a];

I do not understand what makes 2 [a]. It is another senility of C language?

Amazing User
  • 3,473
  • 10
  • 36
  • 75

2 Answers2

5

It is

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

Note: + operator holds commutative property

Sunil Bojanapally
  • 12,528
  • 4
  • 33
  • 46
3

Array subscripting is commutative in C. a[2] and 2[a] and *(a + 2) are equivalent, i.e. the compiler produces the same code. There is a C FAQ for it.

cnicutar
  • 178,505
  • 25
  • 365
  • 392