A 2D array is basically a 1D array of pointers, where every pointer is pointing to a 1D array, which will hold the actual data.
Here N is row and M is column.
dynamic allocation
int** ary = new int*[N];
for(int i = 0; i < N; i++)
ary[i] = new int[M];
fill
for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++)
ary[i][j] = i;
for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++)
std::cout << ary[i][j] << "\n";
free
for(int i = 0; i < N; i++)
delete [] ary[i];
or
delete [] ary;