Inserting a value for an array using malloc
<p>I used this code to insert values for array <code>data</code>, but when I tried inserting the values <code>8 1 2 3 4 5 6 7 8</code>(the first number 8 is the size of the array), the output was <code>00000000</code> instead of the input values <code>1 2 3 4 5 6 7 8</code>. Any idea how I can make the program work?</p>

<pre><code>#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;

int main()
{
  int n,i,*data;

  scanf("%d", &amp;n);

  data=(int *)malloc(sizeof(int)*n);//data[size]

  for(i=0;i&lt;n;i++)
  {
     scanf("%d", &amp;data[i]);
  }

  for(i=0;i&lt;=n;i++)
     printf("%d",data[n]);
  printf("\n");

  return 0;
}
</code></pre>