title: Understanding free() buffer before return statement
body: <p>I want to understand the behavior of returning a pointer from a function call. Suppose I have the following simple code:</p>
  
  <pre><code>int main(){
      int i;
      float *ssd;
      ssd = test();
  
      for (i = 0; i &lt; 3; ++i) {
          printf("%f, ", ssd[i]);
      }
      printf("\n \n");
  
      memset(ssd, 0.0, 3*sizeof(float));
  
      for (i = 0; i &lt; 3; ++i) {
          printf("%f, ", ssd[i]);
      }
      printf("\n \n");
  
  }
  
  float *test(){
  
      float *buff = malloc(3* sizeof(float));
      int i;
      for (i = 0; i &lt; 3; ++i) {
          buff[i] = (float) (6.31 + i);
      }
  
      free(buff);
      return buff;
  
  }
  </code></pre>
  
  <p>As you see, I created a temporary buffer <code>buff</code> inside <code>test()</code>. Before I return, I freed <code>buff</code> before <code>return</code> statement. Although I tested it and the results were as expected, I don't understand how <code>test()</code> function could return <code>buff</code> values even though <code>free(buff)</code> is before <code>return</code> buff? </p>