关于动态分配内存,最后一个数输出时产生错误
#include<stdio.h>#include<stdlib.h>
main(void)
{
int *p,n;
printf("Input n:\n");
scanf("%d",&n);
while(n--)
{
p=(int*)malloc(sizeof(int));
if(p==NULL)
{
printf("Memory alloc fail\n");
exit(0);
}
printf("Input the numbers\n");
scanf("%d",p);
printf("%d\n",*p);
p++;
}
free(p);
}