how to delete a 2d dynamic array in c++

Deleting a 2D Dynamic Array in C++

// Step 1: Free the memory for each row
for (int i = 0; i < rows; ++i) {
    delete[] array[i];
}

// Step 2: Free the memory for the array of pointers
delete[] array;