title: Spatial vs. Temporal locality
body: <p>I understand the definitions of the terms, but I am having trouble applying their concepts to code. For an exercise, we are asked to describe if the following code is spatial or temporal:</p>
  
  <pre><code>for (int i=0; i&lt;10; i++) {
      printf(some_array[i]);
  }
  </code></pre>
  
  <p>I feel like this is spatial locality because when one index of the array is accessed, the next index memory location will be accessed as soon as the loop iterates. Is this the correct way to look at it? What determines if code is temporal versus spatial? More examples would be great.</p>