r/ProgrammerTIL • • Sep 14 '17

Other [c++] Array declarations are commutative/invertible.

array[4] is equivalent to 4[array]. Not that you would ever really use it.

43 Upvotes

14 comments sorted by

View all comments

Show parent comment

2

u/uptotwentycharacters Sep 14 '17

No, because array indexing is syntactic sugar for pointer arithmetic, and pointer arithmetic requires one operand to be a pointer type and the other to be integral type (the order doesn't matter though).