Array of size defined by not constant variable

后端 未结 3 1513
温柔的废话
温柔的废话 2020-12-04 01:49

There is such code:

#include 

int main()
{
  int size;
  std::cin >> size;

  size = size + 1;
  int tab3[size];

  tab3[0] = 5;
  std         


        
3条回答
  •  暖寄归人
    2020-12-04 02:10

    It is a C99 feature, not a part of C++. They are commonly refered to as VLAs(Variable Length Arrays.

    If you run g++ with -pedantic it will be rejected.

    See GCC docs for more info.

    See also: VLAs are evil.

提交回复
热议问题