title: Which ordering of nested loops for iterating over a 2D array is more efficient
body: <p>Which of the following orderings of nested loops to iterate over a 2D array is more efficient in terms of time (cache performance)? Why?</p>
  
  <pre><code>int a[100][100];
  
  for(i=0; i&lt;100; i++)
  {
     for(j=0; j&lt;100; j++)
     {
         a[i][j] = 10;    
     }
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>for(i=0; i&lt;100; i++)
  {
     for(j=0; j&lt;100; j++)
     {
        a[j][i] = 10;    
     }
  }
  </code></pre>