I've been always using arrays whose size are asked in the input by the user like:
int main(){
int n;
cin>>n;
int arr[n];
}
I never faced any problem with this method but now I've read a lot of articles saying that this syntax is not supported by C++ as C++ needs array size at compile time or arrays must be made dynamically using new
keyword. Could anybody make this clear if the above code:
- Is supported by new compilers and not by the old compilers. If yes, then after which version this syntax is supported?
- Allocates the array dynamically in Heap or is this static memory allocation in stack?