title: Speed of C program execution
body: <p>I got one problem at my exam for subject Principal of Programming Language. I thought for long time but i still did not understand the problem</p>
  
  <p>Problem:
  Below is a program C, that is executed in MSVC++ 6.0 environment on a PC with configuration ~ CPU Intel 1.8GHz, Ram 512MB</p>
  
  <pre><code>#define M 10000
  #define N 5000
  int a[M][N];
  
  void main() {
      int i, j;
      time_t start, stop;
  
      // Part A
      start = time(0);
      for (i = 0; i &lt; M; i++)
          for (j = 0; j &lt; N; j++)
              a[i][j] = 0;
      stop = time(0);
      printf("%d\n", stop - start);
  
      // Part B
      start = time(0);
      for (j = 0; j &lt; N; j++)
          for (i = 0; i &lt; M; i++)
              a[i][j] = 0;
      stop = time(0);
      printf("%d\n", stop - start);
  }
  </code></pre>
  
  <p>Explain why does part A only execute in <strong>1s</strong>, but it took part B <strong>8s</strong> to finish?</p>