search

Home  >  Q&A  >  body text

C++的数组可以int n;cin>>n;int a[n];这样初始化吗?

如题,

 `int n;
  cin>>n;
  int a[n];

c++可不可以这样初始化数组啊,在VS2010中不可以,在devc++(编译器gcc) 中可以。

天蓬老师天蓬老师2807 days ago1199

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 14:31:46

    This is the variable length array VLA in the C language C99 standard, which is not supported by the C++ standard. The gcc compiler supports variable-length arrays, but the vc compiler does not. Search for variable length arrays. There will be a lot of information on this (in Chinese and English). Stroustrup, the father of C++, talked about variable-length arrays on his website. There is a short paragraph. If you are interested, you can check it out http://www.stroustrup.com/bs_...

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 14:31:46

    C++ does not support variable length arrays, C supports it

    reply
    0
  • Cancelreply