I'm currently reading the book "C++ Primer" by Lappman. In page 113 It says
The number of elements in an array is part of the array’s type. As a result, the dimension must be known at compile time, which means that the dimension must be a constant expression.
In addition it says we can't do something like this
unsigned cnt = 43; //not an const expression
string bad[cnt]; // error
But it's not true, I compiled it without any problem, I can do even something like this
int i;
cin >> i;
get_size(i);
void get_size(int size) {
int arr[size];
cout << sizeof (arr);
}
And it works well, So why every book say that array size must be known at compile time? Or it must be const expression?