The Question given to me specifically says that a functions takes an integer 2d array and size as parameters. That means, 1) im not allowed to define the size of the array at the declaration. 2) I have to pass the number of rows and cols into the function.
I did it for 1D array previously and it worked, however in the 2D array case it gives a syntax error. I made test codes to check the logic of the syntax. This is the 1D array logic that works. Also this module requires me only to use stido.h library in C. The reason for passing the size of array size is to fill the array in a different function where the loop conditions will take the array size to go through indexes
#include<stdio.h>
void print(int table[],int r);
int main()
{ int r=7,table[r];
print(table,r);
}
void print(int table[],int r)
{ printf("table rows is%d\n",r);
}
However this same logic doesnt work for when I try with a 2D array.(gives a syntax error)
#include<stdio.h>
void print(int table[][],int c,int r);
int main()
{int c=7,r=7,table[c][r];
print(table,c,r);
}
void print(int table[][],int c,int r)
{printf("table rows is\ntable cols is\n",r,c)
}
Can someone kindly explain why this is happening, and suggest a solution for this problem. ? Thanks in advance