Consider the program that prompts the user to input some number and calculate something with those numbers:
Programmer at step 1:
Code:
cout << "How many numbers do you want:";
int n;
cin >> n;
int numbers[1000];
for (int i=0; i<n; ++i)
cin >> numbers[i];
calculate(numbers,n);
Programmer at step 2:
Code:
cout << "How many numbers do you want:";
int n;
cin >> n;
int* numbers = new int[n];
for (int i=0; i<n; ++i)
cin >> numbers[i];
calculate(numbers,n);
delete[] n;
Programmer at step 3:
Code:
cout << "How many numbers do you want:";
int n;
cin >> n;
vector<int> numbers(n);
for (int i=0; i<n; ++i)
cin >> numbers[i];
calculate(numbers,n);
Perhaps you think that the last two are equally good, but they are not! There is a potential memory leak if you forget to delete[] the memory you allocated.
If you think it is extremly easy to remember such a thing, remember that error handling in C++ is done via exceptions, what happens if calculate() throws an exception? The level 3 example handles this, the level 2 does not.