title: Confused between Temporal and Spatial locality in real life code
body: <p>I was reading this <a href="https://stackoverflow.com/questions/4092019/analyse-code-for-spatial-and-temporal-locality">question</a>, I wanted to ask more about the code that he showed i.e</p>
  
  <pre><code>for(i = 0; i &lt; 20; i++)
      for(j = 0; j &lt; 10; j++)
          a[i] = a[i]*j;
  </code></pre>
  
  <p>The questions are,</p>
  
  <ol>
  <li>I understand temporal locality, I think that references to  i and j should be temporal locality. Am I right? </li>
  <li>I also understand spatial locality, as the question I linked answers that references to a[i] should be spatial locality. Am I right? </li>
  <li><p>The person said,</p>
  
  <blockquote>
    <p>"The inner loop will call same memory address when accessing a[i] ten
    times so that's an example for temporal locality I guess. But is there
    spatial locality also in the above loop?"</p>
  </blockquote>
  
  <p>I don't agree with his guess. As the references generated by a[i]
  should be spacial locality (They will be referencing the next
  element in the block). Am I right?</p></li>
  </ol>