Hi,
Can one of you ( pls only experts) explain which one is true first or second? Because we know that in the background processer, there is no 2D, 3D, 4D... dimension for the memory. That is after we want to create one 2D or 3D dimensional array, it is allocated 1D consecutively array in the memory. Pls, do not say you have to deallocate for each element of the array. Can you explain why the first terms are wrong as core (including memory)? Because we do not get any error for the first terms on the compiler. Pls, proof. Thx.
First:
int main()
{
int **container = new int*[n];
for(int i = 0; i < n; ++i)
container[i] = new int[size];
// ... and to deallocate...
delete [] container;
}
Second:
int main()
{
int **container = new int*[n];
for(int i = 0; i < n; ++i)
container[i] = new int[size];
// ... and to deallocate...
for(int i = 0; i < n; ++i)
delete [] container[i];
delete [] container;
}
