Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
Source by cplusplus.com #
 
PREVIOUS NEXT
Tagged: #delete #array
ADD COMMENT
Topic
Name
7+5 =