2

I was surprised to see that below code works in C++.

int n;
cin >> n;
int arr[n];

which is violating most of the information available on internet in this context, that, array size should be compile time known. Is the above feature/behavior is universally rolled out and accepted, or it is just compiler dependent or C++ language version dependent?

saint_sharan
  • 119
  • 1
  • 12
  • it's VLA (variable-length array), a commonly-supported extension, since it is a part of the C standard, but not C++. – user1095108 Jul 02 '21 at 10:42
  • It is compiler dependent, but pretty common. GCC and Clang for example accept to create VLA by default, but not in their -pedantic mode. – Khoyo Jul 02 '21 at 10:50
  • fwiw, there was a proposal to have something similar to VLAs in C++ (i think it was C++14), but it wasn't accepted eventually – 463035818_is_not_an_ai Jul 02 '21 at 11:19

0 Answers0