malloc
我一直都知道,如果不使用and就无法在 C 中构建动态数组free
,那么为什么这段代码可以正确编译和运行呢?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
printf("Insert a number: ");
scanf("%d", &a);
int array[a];
int i;
for(i=0; i<a; i++)
{
array[i] = rand();
}
for(i=0; i<a; i++)
{
printf("%d\t", array[i]);
}
puts("");
return 0;
}
我知道这不是一个真正的动态数组,因为在声明后无法更改“数组”的大小,也无法释放调用free()
,但我仍然认为静态数组的大小必须在编译时间显然不是这里的情况..