In C++ books, array bound must be constant expression, but why the following code works?

前端 未结 2 1950
感情败类
感情败类 2020-11-22 13:13
#include 
using namespace std;

int main(){
    int n=10;
    int a[n];

    for (int i=0; i

        
2条回答
  •  孤独总比滥情好
    2020-11-22 14:14

    This a a C99 feature called VLA which some compilers also allow in C++. It's allocation on stack, just as it would be with int a[10].

提交回复
热议问题