search

Home  >  Q&A  >  body text

C++编译器在分配这样的第一维是变量第二维确定的数组的时候是怎么分配的啊?

    int length;
    cin>>length;
    int arr[length][2];

比如这个,length 待输入,编译器在为 arr 分配空间的时候,遇到length怎么办,是直接把length当成int的最大值来分配吗?

g++ ,我也很奇怪,不能理解为什么

大家讲道理大家讲道理2773 days ago290

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 14:29:02

    This is a new addition to the c99 specification, a variable-length array. The length of the array is determined during runtime and cannot be changed once determined.
    You can check out this blog: http://rangercyh.blog.51cto.c...

    reply
    0
  • 黄舟

    黄舟2017-04-17 14:29:02

    I use vs2012, which does not support variable length arrays. It seems that the latest C++ standard supports it, but I have never seen any compiler support it

    reply
    0
  • Cancelreply