My textbook states that "The advantage of dynamic allocation is that it is not necessary to know the size of the array at compile time." And they give this example:
cout << "how many entries?";
cin >> numEntries;
double * dPtr = new double[numEntries];
cout << "Enter your values.\n";
for (int i = 0; i < numEntries; i++) {
cin >> dPtr[i];
}
However I rewrote this code with static allocation and it works exactly the same way AFAIK:
int numEntries;
cout << "How many entries? ";
cin >> numEntries;
double arr[numEntries];
cout << "Enter your values.\n";
for (int i = 0; i < numEntries; i++) {
cin >> arr[i];
}
So, what were they trying to say?
EDIT: I'm using gcc version 8.1.0