title: Dynamic memory allocation in each iteration of for loop to make dynamic array
body: <p>what's the problem with this code? i am trying to allocate 1 int size memory every time for loops run, but this code doesn't print anything</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  int main()
  {
      int *a;
      for(int i=0;i&lt;5;i++)
      {
          a=(int *)malloc(1*sizeof(int));
          a[i]=i;
      }
      for(int i=0;i&lt;5;i++)
      {
          printf(&quot;%d\n&quot;,a[i]);
      }
      free(a);
  
  }
  </code></pre>