Answer the question
In order to leave comments, you need to log in
How to pass a two-dimensional static array to a C function?
There is an array char mass[1024][1024]
and a function int fun(char*)
. When inserting a function fun(mass)
, the compiler issues a warning about type mismatch, you have to type cast fun((char*)mass){}
or fun((char*)&mass){}
. Is it possible to specify a static array as an argument? And why are the types different?
Answer the question
In order to leave comments, you need to log in
The whole array is not passed to the function (unless it is wrapped in a structure), but a pointer to its 0th element is passed, and the formal argument of the function must be a pointer to the type of array elements passed by the actual argument.
An n -dimensional array is a 1 - dimensional array of (n-1) -dimensional arrays and, accordingly, the formal argument of the function must be a pointer to an (n-1)-dimensional array.
In this case
int fun(char (*)[1024]);
int fun(char (*m)[1024]) {/*...*/}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question