這是我的理解,C++編譯器不會允許您用變量初始化數組,但此程序編譯並在我的計算機上運行,爲什麼?爲什麼這個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++編譯器不會允許您用變量初始化數組,但此程序編譯並在我的計算機上運行,爲什麼?爲什麼這個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");
}
您正在使用哪種編譯器?其中一些擴展名爲*可變長度數組。* – jaggedSpire
@fred這意味着編譯器有其自己的語言擴展,允許使用VLA。你應該關閉它們以獲得編譯器錯誤消息。 –