+ 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

30th Sep 2020, 12:24 PM
kellouche dhiya
kellouche dhiya - avatar
3 Answers
+ 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/
30th Sep 2020, 12:31 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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🙏🏻
30th Sep 2020, 12:38 PM
kellouche dhiya
kellouche dhiya - avatar