+ 1
C++ Array subscript
Why does this give 4? What kind of syntax is this? int mat[2][2] = {{1,2},{3,4}}; cout << 1[mat[1]];
1 Answer
+ 3
Probably easier to imagine a 1D array first.
arr[1] is the same as *( arr + 1 )
If you switch them around, 1[arr], you get *( 1 + arr )
Since the + operator is commutative the result stays the same.
So for your 2d array, 1[mat[1]], it becomes *( 1 + *( mat + 1 ) ) instead of
mat[1][1], *( *( mat + 1 ) + 1 ).