For example, if you have some code that takes an integer as input and then declare an array of that size, like this:
#include <iostream>
using namespace std;
int main(){
size_t NUM;
cin >> NUM;
size_t array[NUM];
//do whatever
return 0;
}
How does this not give an error when compiling? The compiler should set aside a specific part of memory for the array, but how can it do that when the size is NUM, and is not known during compilation? Does the compiler automatically convert it to a dynamic array with new?
I am using g++ 7.3.0 compiler.
Thank you!