<分区>
据我了解,C++ 编译器不允许您使用变量初始化数组,但此程序在我的计算机上编译并运行,这是为什么?
// this should not compile because there is a variable in the array declaration
#include <iostream>
int main(){
int x = 5;
int ar[x];
printf("hello world\n");
}
标签 c++ arrays compilation
<分区>
据我了解,C++ 编译器不允许您使用变量初始化数组,但此程序在我的计算机上编译并运行,这是为什么?
// this should not compile because there is a variable in the array declaration
#include <iostream>
int main(){
int x = 5;
int ar[x];
printf("hello world\n");
}
最佳答案
In C++, variable length arrays are not legal. G++ allows this as an "extension" (because C allows it), so in G++ you can do this.
关于c++ - 为什么这个c++程序可以编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41369494/