Say I have the follow C++ code:
int *arr = new int[5];
int *new_arr = new int[10];
delete[] arr;
arr = new_arr;
delete[] arr;
Will the final delete[] statement work properly? My thinking is that it wouldn't, because the last time arr was set using new[], it pointed to 5 ints, but now it points to 10 ints, so delete[] will only deallocate 5 ints. However, many tutorials on dynamic arrays seem to do this, so am I missing something?