Possible Duplicate:
Why does the order of the loops affect performance when iterating over a 2D array?
I have this simple for loops
for (i=0;i<10000;i++){
for(j=0;j<10000;j++){
a[i][j]=i+j;
}}
when I change the order of these for loops to:
for (j=0;j<10000;j++){
for(i=0;i<10000;i++){
a[i][j]=i+j;
}}
I see that the runtime increases dramatically. Why this happen?
thanks