title: Does local variable be deleted from memory when this function is called in main
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope">Can a local variable&#39;s memory be accessed outside its scope?</a><br>
    <a href="https://stackoverflow.com/questions/11876772/returning-address-of-local-variable">returning address of local variable</a>  </p>
  </blockquote>
  
  
  
  <p>I have a question, first of all look at the code</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
  
  int sum();          /* function declaration */
  
  int main()
  {
      int *p2;
      p2 = sum();         /* Calling function sum and coping its return type to pointer variable p2  */
      printf("%d",*p2);
  } /*  END of main  */ `
  
  int sum()           
  {
      int a = 10;
      int *p = &amp;a;
      return p;
  } /*  END of sum */
  </code></pre>
  
  <p>I think the answer is 10 and address of variable a, but my tesacher says that a is local to the function come so a and its 
  value will be deleted from the memory location when the function returns or is finished executing. I tried this code and the answer is weel of course 10 and address of a, I use the GNU/GCC compiler. Can anyone say what is right and wrong. 
  Thanks in advance. </p>