Hacker News new | ask | show | jobs
by teo_zero 717 days ago
Another source of surprise:

  4[arr] // same as arr[4]
2 comments

Thanks to array decay to pointer, we basically have `*(array_label+offset)` which in this case of yours we have `*(offset+array_label)`; in other words, `*(arr+4)` is the same as `*(4+arr)`...that's it, really!
By the same principle, these are exactly the same:

  arr[i][j]
  j[i[arr]]
These are the simplifications you'd do. You only need to know that a[x][y] is equivalent to (a[x])[y], and that a[x] is the same as x[a].

  arr[i][j]
  (arr[i])[j]
  (i[arr])[j]
  j[i[arr]]