title: why does this function return garbage value
body: <p>I was writing a program and facing this problem that the following function used to return garbage values:</p>
  
  <pre><code>int* foo(int temp){
     int x = temp;
     return &amp;x;
  }
  </code></pre>
  
  <p>When I modified it to this, it worked fine:</p>
  
  <pre><code>int* foo(int *temp){
      int *x = temp;
      return x
  }
  </code></pre>
  
  <p>What was wrong with the first version?</p>