title: Segmentation fault on program with scanf
body: <p>This is a small piece of code that I made while trying to understand how malloc and pointers work.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int *buffer (int count)
  {
    int *buffer = malloc (count * sizeof(int));
  
    for (int i = 0; 0 &lt;= i &amp;&amp; i &lt; count; i++)
      {
        buffer[i] = 0;
      }
  
    return &amp;buffer;
  }
  
  int main ()
  {
    int size = 0;
    int i = 0;
    scanf ("%d", &amp;size);
  
    int *num = buffer (size);
    while (i &lt; size)
      {
        scanf ("%d", &amp;num[i]);
        i++;
      }
  }
  </code></pre>
  
  <p>For some reason that I can't understand, I keep getting a segmentation fault. This error repeatedly happens on the last scanf() and I do not know why. I know i have to pass pointer to scan f and num is already a pointer so i thought that i would not need to include the &amp;. But, I received a segmentation fault earlier if i do not. Also, I believe I have allocated the correct amount of space using malloc but I am not sure. Any help with what is happening here would be appreciated.</p>