Consider the following way of working with a dynamically allocated two-dimensional array (for some reason, this way does not appear among the replies here):
const int nRows = 2, nCols = 3;
int (*arr)[nCols] = (int(*)[nCols])(new int[nRows * nCols]);
arr[1][1] = 2;
std::cout << arr[1][1] << endl;
delete[] arr;
Does delete[]
in the last line free the memory correctly in this case?