Why is it worse to initialize a two dimensional array like this?
问题 for(int i = 0; i<100; i++) for(int j = 0; j<100; j++) array[j][i] = 0; // array[i][j] = 0; My professor said it was much more costly to initialize a two dimensional array in the first way as opposed to the second. Can someone explain what is going on underneath the hood which makes that the case? Or, do the two means of initialization have equal performance? 回答1: As @dlev mentioned, this is due to locality of reference and has to do with how the physical hardware in the computer works. Inside