The following code compiles but runs with mistake:
int main() {
int (*d)[2] = new int[3][2];
// do something
delete [] *d; // this is wrong
delete [] *(d+1); // this is also wrong
//delete [] d; // this works
return 0;
}
I do not know why "delete [] *d" does not work because *d seems to be a pointer to a chunk containing 2 integers and delete[] should destroy that chunk.
Furthermore, I am not sure whether "delete [] d" is enough to release all six elements since two-dimension array is involved here.
Thanks!
deletewhat younew, and only what younew. The new-expression here returnedd, not*dand not*(d+1).int (*d)[2]says "*dis an array of two ints". An array is not a pointer.