2d array dynamic memory allocation

How can i make memory free for the 2d array dynamically allocated?

Hey @sagar_aggarwal you have to run a loop based on number of columns (let’s name it c)of you dynamically allocated array(let’s name it p). and have to do this:

for(int i = 0; i < c; i++)
    free(p[i]);
free(p);

but in c++ i have to use delete operator.

Then do this


  //Free each sub-array
   for(int i = 0; i <c;++i) {
        delete[] p[i];   
    }
    //Free the array of pointers
    delete[] p;