+ 1
Passing 2d array in function
How i can pass a 2D array in function int mtx[2][3]; int MAX; MAX = arr_max(mtx); <~~ here i got in error
3 Respuestas
+ 4
See this
There are three ways to pass a 2D array to a function:
The parameter is a 2D array
int array[10][10];
void passFunc(int a[][10])
{
// ...
}
passFunc(array);
The parameter is an array containing pointers
int *array[10];
for(int i = 0; i < 10; i++)
array[i] = new int[10];
void passFunc(int *a[10]) //Array containing pointers
{
// ...
}
passFunc(array);
The parameter is a pointer to a pointer
int **array;
array = new int *[10];
for(int i = 0; i <10; i++)
array[i] = new int[10];
void passFunc(int **a)
{
// ...
}
passFunc(array);
For better explanation you can read this post .i copied these from stack overflow
https://www.google.com/amp/s/www.geeksforgeeks.org/pass-2d-array-parameter-c/amp/
+ 1
♨️♨️ i can't use the way number three to solve my problem becouse i'm using C . So i think malloc and calloc can do the work 😃 . Thank u🙏🏻