While writing some code, I realised one of my code works which as per my understanding shouldn't be working. The code is
int main() {
int val;
cin>>val;
int array[val];
}
No only this, even the code below is also working
int main() {
int valone = rand();
int valtwo = rand();
int array[valone][valtwo];
}
I always had the understand that static arrays needs constant values, or the values which could be deduced by compilers during compile time.
Is there any change in recent C++11/14 specification or this was true for C++ since beginning.
NOTE: Visual Studio Compiler does gives an error in this case, but
g++
as well asclang
successfully compiles above code