title: Memory allocation for global and local variables
body: <p>I have learnt that memory for global variables are allocated at program startup whereas memory for local variables are allocated whenever function call is made.  </p>
  
  <p><strong>Case 1:</strong><br>
  I have declared a global integer array of size 63500000 and memory used is 256 MB<br>
  <a href="http://ideone.com/9x4f1" rel="noreferrer">Ideone Link</a></p>
  
  <pre><code>include &lt;stdio.h&gt;
  int a[63500000];
  int main()
  {
      printf ("This code requires about 250 MB memory\n");
      return 0;
  }
  </code></pre>
  
  <p><strong>Case 2:</strong><br>
  I have declared a local integer array of same size in main() and memory used is 1.6 MB<br>
  <a href="http://ideone.com/6Hd17" rel="noreferrer">Ideone link</a></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main()
  {
      int a[63500000]= {1,5,0};
      printf ("This code requires only 1.6 MB \n");
      //printf ("%d\n", a[0]);
      return 0;
  }
  </code></pre>
  
  <p><strong>Case 3:</strong><br>
  I have declared a local integer array of same size in another function and memory used is 1.6 MB<br>
  <a href="http://ideone.com/K88cf" rel="noreferrer">Ideone Link</a></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void f()
  {
      int a[63500000];
  }
  
  int main()
  {
      f();
      return 0;
  }
  </code></pre>
  
  <p>Please explain why there is difference in memory used or my concept of memory allocation is wrong ??</p>