title: When is memory allocated to local variables in C
body: <p>As local variables are also called automatic variables, and are supposed to be allocated memory at run time, when function is accessed.</p>
  
  <pre class="lang-c prettyprint-override"><code>int main(){
      int a; // declaration 
      return 0;
  }
  
  int main(){
      int a[]; // compilation error, array_size missing
      return 0;
  }
  
  int main(){
      int a[2]; // declaration, but can't work without array_size, 
                // so at compile time it is checked!
      return 0;
  }
  </code></pre>
  
  <p>My question is whether it's just a rule to give array_size in declaration in C, or memory is allocated at compile time for array (still local variable)</p>
  
  <p>How does it work?</p>
  
  <p>An array is a variable as per C programming by K&amp;R. pg no 161.</p>