I'm trying to read from a 2D array I have declared in my main function but while being in a different function. I thought that if I will send a pointer to the first cell of that array then this will be possible, however I'm still having problem doing it
The issue is passing a 2d array which I have declared in my main function to another function, which itself is called from another function. I know this is a basic question but after many tries I still can't understand what I'm doing wrong and would sincerely appreciate your help.
I've simplified the following code the problem in the following code:
void main(){
N = 5, M = 4
double arr[][4] = {
{ 1,2,1,5 },
{ 8,9,7,2 },
{ 8,7,6,1 },
{ 5,4,5,3 },
{ 5,4,5,3 }
};
double(*pointer)[4]; // pointer creation
pointer = arr; //assignation
function_1(pointer ,N,M);
}
function_1(double *arr, int N, int M){
function_2(arr,N,M);
}
function_2(double *arr, int N, int M){
int c = 0;
for(int i=0; i<n; i++){
for(int j=0l j<M; j++){
arr[i][j] = c; // error while trying to read from arr[i][j]
c += 1;
}
}
}