I thought that built-in arrays in C++ are statically allocated. But the following code works:
//...
int x;
std::cin >> x;
const int cx = x;
int array[cx];
//...
Why does it?
I thought that built-in arrays in C++ are statically allocated. But the following code works:
//...
int x;
std::cin >> x;
const int cx = x;
int array[cx];
//...
Why does it?
Variable length arrays are not part of the C++ standard, however your compiler allows it. If you use the -pedantic-errors
option with your compiler (assuming g++), this will throw an error as that option strictly enforces the standard.