Two-dimensional array as function argument

How to pass a two-dimensional array as an argument to a function (it is believed that the size of the array is known)? I will need help for both declaring and defining a function. What I mean is something like this:

#include <stdio.h> #define size 10 void function(int anarray[size][size]); //<- Is that correct? ... void function(int anarray[][]) //<-Is this too? { } 

Thanks a lot!

+4
source share
1 answer
 void function1(int anarray[size][size]); // <- Is that correct? 

Yes it is. void function1(int anarray[][size]); will work too.

 void function1(int anarray[][]) // <- Is this too? 

No, this is a compiler error. Only the first (internal) dimension of the array breaks into a pointer when passing the function.

+6
source

Source: https://habr.com/ru/post/1487763/


All Articles