Hot answers tagged

11

Such an effect happens because of how the data of the int** a is stored in memory (as per C/C++). This question on StackOverflow has answers with some more details (in particular, a difference between int** and int[][] that many users noted in the comments), and how it looks like an array of arrays - it's just laid out contiguously in memory. It's worth ...


3

Noting correctly that this is an array of pointers to arrays of ints: In the first version, the code is accessing element 0 of each successive array of ints, then element 1, etc. That means it is changing which pointer (to an array of ints) is being dereferenced on each inner iteration. In the second version, the code is accessing each element of the 0'th ...


Only top voted, non community-wiki answers of a minimum length are eligible