I got the code correct but i have 2 doubts which are:
- how to pass a 2d array to a function without passing its size?
- whats the upper limit of 2d array?
char maze[2000] wasn’t working but char maze[1005] did work.
I got the code correct but i have 2 doubts which are:
1.You can pass a 2D vector, but to pass a simple array you will need to pass the size in one way or another.
2. Array size will depend on system, normally global array size is 10^7-10^8 and local array can be 10^7 -10^6 (these are size of linear array, you can get idea about 2D array from this).
If this solves your doubt mark it as resolved , if you have any other doubt please ask me.
Thanks for your reply.
For linear array, I don’t face problems due to size but in 2-d arrays this problem occurs.
I don’t know how to get the idea of size of 2d array from 1-d array.
also can you tell how to pass 2d array only using pointer to pointer approach?
void passFunc(int **a, int r ,int c)
{
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
cout<<a[i][j]<<" “;
cout<<”\n";
}
}
int main()
{
int **array;
array = new int *[10];
for(int i = 0; i <10; i++)
array[i] = new int[10];
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
array[i][j]=j;
}
passFunc(array,10,10);
}
I hope this piece of code helps in understanding how to pass 2D array using pointer to pointer.
As for the dimensions of the array , if it is int then product of both should normally be less than 10^6/10^7 , if it is string or some structure allowed size is even less (10^3/10^4).
Their is no rule that puts the upper limit on the array size but we have limited memory available that limits the size.