-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?

Dima
  • 3,363
  • 9
  • 31
  • 69

2 Answers2

5

It is

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

Note: + operator holds commutative property

Sunil Bojanapally
  • 11,964
  • 4
  • 34
  • 43
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
  • 172,020
  • 25
  • 347
  • 381