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.
Rat in a maze - Creating 2D array
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.