title: Are variables on the stack "statically allocated"?
body: <p>I was reading <a href="http://es.gnu.org/~aleksander/valgrind/valgrind-memcheck.pdf" rel="nofollow">this article</a> and saw this: "This article assumes that you already know and understand at least basically how the memory
  map in GNU/Linux system works, and specially the difference between memory statically
  allocated in the stack and memory dynamically allocated in the heap."</p>
  
  <p>This confused me because I thought that stack and heap are dynamically allocated, meaning only allocated if necessary, and global variables and variables declared as "static" inside of a function are statically allocated, meaning always allocated.</p>
  
  <p>For example, if I have</p>
  
  <pre><code>void f() {
      int x = 1;
      ...
  }
  </code></pre>
  
  <p>the value 1 only gets put on the stack and the stack pointer only gets incremented if the function f() gets called. Likewise, if I have</p>
  
  <pre><code>void f() {
      int x = malloc(1 * sizeof(int));
      ...
  }
  </code></pre>
  
  <p>that heap memory only gets allocated if f() is called. However, if I have "int x = 1;" in the global section of the program or "static int x = 1;" within a function body, any time I run this program, that memory will be allocated in the data section with the value 1. </p>
  
  <p>Am I wrong about any of this?</p>