Array of size defined by not constant variable

后端 未结 3 1526
温柔的废话
温柔的废话 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:13

    GCC provide's VLA's or variable length arrays. A better practice is to create a pointer and use the new keyword to allocate space. VLA's are not available in MSVC, so the second option is better for cross platform code

提交回复
热议问题