I have the following code:
int **arr = new int*[5];
for(int i = 0; i < 5; ++i)
arr[i] = new int[];
for(int i = 0; i < 5; ++i)
delete [] arr[i];
delete [] arr;
Now it compiles and runs successfully, however if I remove the array size '5' from the first line the code compiles but crashes with run-time error on the last line. I have the following questions that I have failed to find answers in Straustrup's C++ book, in the internet etc.
- Why the code crashes in the specified case ? (My guess is that delete [] fails to find the array size to be deleted and crashes.)
- If it is not allowed to allocate multidimensional arrays without indicating the size why such errors are not caught by compiler at compile time ?