Answers for "c++ dynamic 2d array deletion"

C++
5

delete 2d dynamic array c++

for (int i = 0; i < numRows; i++) {
    delete [] world[i];
//    world[i] = 0;  // <- don't have to do this
}
delete [] world;  // <- because they won't exist anymore after this
world = 0;
Posted by: Guest on June-12-2020
1

delete specific row from dynamic 2d array c++

string** new_array = array;
for(int i=0; i<numRows; i++){
  new_array = new string[coloumns]
    if(i != n){ // <- if you want to delete nth row then
        new_array[i] = array[i];
    }
}
array = new_array; // <- now array excluding nth row is saved in this pointer.
Posted by: Guest on December-09-2021

Browse Popular Code Answers by Language