Answers for "c++ allocate and free dynamic 2d array"

C++
0

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
Posted by: Guest on August-29-2021

Browse Popular Code Answers by Language