title: C behavior (non initialized values)
body: <p>I had a question regarding a C code. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void foo(void){
          int a;
          printf("%d\n",a);
  }
  
  void bar(void){
          int a = 42;
  }
  
  int main(void){
          bar();foo();
  }
  </code></pre>
  
  <p>Apparently I am supposed to get a 42 as a result at the end of compilation.  <a href="http://www.slideshare.net/olvemaudal/deep-c" rel="nofollow">http://www.slideshare.net/olvemaudal/deep-c</a>  , slide #126. But when I compile it on my machine I get garbage values <code>(gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5))</code> </p>
  
  <p>Do I need to turn off some optimization? Or is the author of the slide wrong about this? Can someone explain what should be the result of the code? If it is 42, could you also explain how/why? Also, would the result be any different on a C++ compiler (g++). </p>