Answers for "cpp dynamic array 2d"

C++
1

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
21

how to make a n*n 2d dynamic array in c++

int** a = new int*[rowCount];
for(int i = 0; i < rowCount; ++i)
    a[i] = new int[colCount];
Posted by: Guest on April-04-2020

Browse Popular Code Answers by Language