是可变长度数组在c ++? [英] Are variable length arrays there in c++?
本文介绍了是可变长度数组在c ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直认为c ++中不允许使用可变长度数组(请参阅:可变长度数组在C ++?)。但为什么这个代码编译和工作?
I had always thought that variable length arrays were not allowed in c++(Refer :Variable length arrays in C++?) .But than why does this code compile and work?
#include <iostream>
using namespace std;
int main () {
int n;
cin >> n;
int a[n];
for (int i=0; i<n; i++) {
a[i] = i;
}
for (int i=0; i<n; i++) {
cout << a[i] << endl;
}
}
推荐答案
当前C ++标准不需要编译器VLA。但是,编译器供应商允许支持VLA作为扩展。
The current C++ standard does not require that compilers VLAs. However, compiler vendors are permitted to support VLAs as an extension.
最初建议VLA出现在C ++ 14中,但是建议没有成功。他们可能会返回C ++ 17。
It was originally proposed that VLAs would appear in C++14, however the proposal did not succeed. They may return for C++17.
这篇关于是可变长度数组在c ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文