#include <stdio.h>
#include <math.h>
int size = (int) sqrt(4);
int arr[size];
int main() {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到了:
test.c:5: error: array bound is not an integer constant
Run Code Online (Sandbox Code Playgroud)
有人能帮助我吗?
您无法使用可变大小的静态存储(例如"全局"数组)定义数组.如果阵列具有自动存储(如果它是函数中的数组),它将作为VLA工作.
正如icepack正确指出的那样,在C99中正式引入了VLA.