title: Memory: how does the compiler choose where to store variables?
body: <p>Given two functions, func1 and f2, with the following signatures:</p>
  
  <pre><code>void func1(){
      int baba = 12345;
      // printf the value of baba here
  }
  
  void f2(){
      int loo;
      //printf the value of loo here
  }
  </code></pre>
  
  <p>...if I run my int main, which only has func1 then f2:</p>
  
  <pre><code>int main(){
        func1();
        f2();
  }
  </code></pre>
  
  <p>...then the printed value of both baba and loo will be 12345.  So my question is as follows:</p>
  
  <ol>
  <li><p>Is this defined behaviour, or just something erroneous that my machine does?</p></li>
  <li><p>If this isn't some erroneous thing my computer did, can you explain why the compiler chooses to store <code>loo</code> in the same address as <code>baba?</code></p></li>
  </ol>
  
  <p><strong>EDIT:</strong>  I guess I should ask, if I have these EXACT two functions, will     baba and loo have the same value on ANY machine?</p>
  
  <p>I understand loo's value is the result of baba's leftover  bits, and I understand that (on my machine, at least) the stacks of both are being laid out such that loo overlaps onto baba's old territory.  <em>Is it true</em> that every machine would lay these two function stacks out in such a manner that baba and loo overlap?  Using these two functions exactly as written, that is...</p>