我看到一些这样的代码:
int foo()
{
int sz = call_other_func();
char array[sz];
/* whatever */
}
我对它如何工作甚至用 gcc
编译感到困惑。数组的大小应该是静态的 并在编译时确定,不是吗?
最佳答案
这种类型的数组称为variable length arrays (您还想阅读:Arrays of Variable Length - GCC)并且只允许在 C99 中使用。通过使用 VLA,可以在运行时确定数组的大小。
关于c - 数组大小在运行时确定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20096253/