I just read a tutorial about dynamic memory in C++ and it states as follows:
...the size of a regular array needs to be a constant expression, and thus its size has to be determined at the moment of designing the program, before it is run...
However, I just ran a program to test this:
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
int y;
cout << "Enter number of elements of array: ";
cin >> y;
int x[y]; // I declared an array using a variable size instead of a constant expression
x[y-1] = 3;
cout << x[y-1];
return 0;
}
...and there were no errors. So is the statement made by the tutorial incorrect or am I misinterpreting it?