#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
int size;
cin >> size;
int myArray[size]; //this shouldn't compile , right ?
return 0;
}
I thought this wouldn't compile, but it does actually (using the g++ command).
What I found out later is that GCC actually allows variable-size arrays even if by standard C++ doesn't support variable-size arrays, Which is weird ! Because I hear everyone saying that the only way to create a variable-size array is to use dynamic allocation like int* array = new int[size];
or better std::vector
. I thought GCC wouldn't allow that piece of code !
Anyway, My theoretical question is, the myArray
array is allocated in the heap or stack area ?