Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ allocate and free dynamic 2d array

// allocate
int** matrix = new int*[rowCount];
for(int i = 0; i < rowCount; i++)
    matrix[i] = new int[colCount];

// free
for(int i = 0 ; i < rowCount; i++)
    delete[] matrix[i];	// delete array within matrix
delete[] matrix;	// delete actual matrix
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #allocate #free #dynamic #array
ADD COMMENT
Topic
Name
5+1 =