c语言动态分配问题大家帮帮我
#include "stdio.h"
#include "stdlib.h"
int main()
{
int i, n;
int *p;
scanf("%d", &i);
p = (int *)malloc(i);
if (p == NULL)
exit(1);
{
for (n = 0; n < i; n++)
scanf("%d", &p[n]);
for (n = 0; n < i; n++);
printf("%d", p[n]);
}
free(p);
return 0;
}
1回答
-
___C___
两个错误,1、p = (int *)malloc(i*sizeof(int)); 2、for (n = 0; n < i; n++); 后面不能加分号(“;”),要改为for (n = 0; n < i; n++)