Array of non-constant size: Why does this even work?
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 6 7 8 9 10 | #include <iostream> using namespace std; int main(){ int n; cout<<"Enter the size :"; cin>>n; int array[n]; // I've worked some outputs and it works return 0; } |
这是一种动态分配吗?
为什么它甚至没有给出" n"为" const"的错误?
另外,写入
我正在使用Dev-C ++。
显然,可以在C99中声明可变长度数组,而且GCC似乎也接受C ++。
Variable-length automatic arrays are allowed in ISO C99, and as an
extension GCC accepts them in C90 mode and in C++. These arrays are
declared like any other automatic arrays, but with a length that is
not a constant expression.
你每天都学到一些东西..我以前从未见过。