想要动态地创建一个数组,但是代码运行后提示segmentation fault
#include<stdio.h>#include<stdlib.h>
void main(void)
{
int n;
int i;
int *square=NULL;
printf("Enter the side of a square here: \n");
scanf("%d",n);
square=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
square=n;
}
for(i=0;i<n;i++)
{
printf("%d",square);
}
free(square);
}
//这里要用取址符
scanf("%d",&n);
页:
[1]