is it possible?
I realized I couldn't do it and decided to google for it. nothing found.. .so I ask your help.
Thank you
Passing bidimentional mtrx to functions as pointer argument
Moderator: Board moderators
it is possible to pass anything, it's just that things get complicated fast the more u reference.
if u have
int mat[N][M]; => void doSomething(int m[][M]); //or int *m[M]
(this is an array of arrays of int)
int *mat[M]; => void doSomething(int *m[M]); // or int **m
(this is an array of pointers to int, which can b allocated dynamically to int [][])
(this is what the main args uses
)
the point is that when sending an array as parameter to a function, it 'decays' into a pointer. The first size value can be omitted since u are responsable for not surpassing allocated memory. any other size values are necessary to acces values in the table.
though complicated, reading here will explain:
http://www.eskimo.com/~scs/C-faq/s6.html
btw the page where that comes from is one of my c favourites, lots of help:
http://www.eskimo.com/~scs/C-faq/top.html
hope this helps!
if u have
int mat[N][M]; => void doSomething(int m[][M]); //or int *m[M]
(this is an array of arrays of int)
int *mat[M]; => void doSomething(int *m[M]); // or int **m
(this is an array of pointers to int, which can b allocated dynamically to int [][])
(this is what the main args uses

the point is that when sending an array as parameter to a function, it 'decays' into a pointer. The first size value can be omitted since u are responsable for not surpassing allocated memory. any other size values are necessary to acces values in the table.
though complicated, reading here will explain:
http://www.eskimo.com/~scs/C-faq/s6.html
btw the page where that comes from is one of my c favourites, lots of help:
http://www.eskimo.com/~scs/C-faq/top.html
hope this helps!
Understanding a problem in a natural way will lead to a natural solution