title: When memory is allocated to a function (definition or call)
body: <p>When the memory is allocated to a function.
  For example:
  </p>
  
  <pre><code>int doubleMe(int smthng){ 
  int dbl = 2*smthng; //line 2
  return dbl; 
  } 
  
  void main(){ 
  int var; 
  printf("The double of var is: %d",doubleMe(var)); //line 8
  }
  </code></pre>
  
  
  
  <p>When is memory allocated to variable <code>dbl</code>?</p>
  
  <ul>
  <li>when is defined (line 2) (compile time)</li>
  <li>or when function is called (line 8)(run time)</li>
  </ul>
  
  <p>I believe it is allocated when function is called(run-time) in stack. And freed when function exits, is it? Would be great if someone could please explain it better.</p>
  
  <p><a href="https://stackoverflow.com/questions/11406576/c-function-memory-allocation">This question</a> looks similar but not quite!</p>