Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
Comment

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.
Comment

new and delete 2D array

// let's say we want to dynamically make int[Y][X]:
int** superevil = new int*[Y];
for(int i = 0; i < Y; ++i)
  superevil[i] = new int[X];

// now we can do this:
superevil[2][3] = 1;

// but cleanup is just as ugly as allocation:
for(int i = 0; i < Y; ++i)
  delete[] superevil[i];
delete[] superevil;
Comment

PREVIOUS NEXT
Code Example
Cpp :: qt messagebox 
Cpp :: c++ chrono 
Cpp :: qt qimage load from file 
Cpp :: temporary mobile number 
Cpp :: access last element in vector in c++ 
Cpp :: cuda extern __shared__ 
Cpp :: c++ random number generator 
Cpp :: distinct colors cses solution 
Cpp :: how to remove spaces from a string 
Cpp :: c++ remove space from string 
Cpp :: c++ string to double 
Cpp :: use c++17 g++ 
Cpp :: qt double en qstring 
Cpp :: quadratic problem solution c++ 
Cpp :: locate specific string letters c++ 
Cpp :: how to print fixed places after decimal point in c++ 
Cpp :: extends c++ 
Cpp :: c++ print number not in scientific notation 
Cpp :: lcm function c++ 
Cpp :: min element c++ 
Cpp :: C++ Program to Reverse an Integer 
Cpp :: c++ length of char* 
Cpp :: c++ case 
Cpp :: iterating in map/unordered map c++ 
Cpp :: c++ random number 0 to 1 
Cpp :: how to make a list in c++ 
Cpp :: return array from function c++ 
Cpp :: max_element c++ 
Cpp :: double to int c++ 
Cpp :: vector reverse function in c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =