Y
Hacker News
new
|
ask
|
show
|
jobs
by
teo_zero
717 days ago
Another source of surprise:
4[arr] // same as arr[4]
2 comments
stefanos82
717 days ago
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!
link
trealira
716 days ago
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]]
link