I have tried a few lines of code that allows the user to determine an arrays size at runtime (without using dynamic memory) and it should produce an error before compiling. However, when I compile and run in codeblocks everything works fine, I can even enter the amount of elements I want in the array. I thought this was strange so I went to visual studio and pasted the code, I wasn't even able to compile the program (the error tells me that the array's size needs to be a constant value... the normal, expected error). Someone please explain this to me, it is making me really confused when trying to understand the need for dynamic memory allocation.
#include <iostream>
#include <time.h>
#include <cstdlib>
usingnamespace std;
int main()
{
srand(time(0));
int amountMonsters=0;
cout << "Please enter how many monsters you want to have in the game: ";
cin >> amountMonsters;
int nArray[amountMonsters];
return 0;
}
ASFAIK, that is standards compliant for C99 (which I believe isn't really used, they do weird things). So your version of G++ might support it, it seems like.