Rat in a maze - Creating 2D array

Hello sir/ma’am, i am trying to create a 2d array dynamically but i am not getting what column size to pass while using as an argument in function call. As creating dynamically, value of m i.e. columns is not known before hand and if pass ‘m’ then it will show error. Also I feel creating a static array- maze[1000] [10000] and soln[1000][1000] will waste a lot of space. So please guide me what to do.

Sharing my code: https://ide.codingblocks.com/s/162355

Hi @priyanshi.agarwal3405

A dynamic 2D array is basically an array of pointers to arrays. You can initialize it using a loop, like this:

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

When you are creating array dynamically then in function you have to declare array like this :

int **array = new int *[rows];
for(int i = 0; i <rows; i++)
array[i] = new int[cols];

void passFunc(int **a) {
// …
}

passFunc(array);

Okay, Thank you sir.