Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将二维数组作为函数的参数传递(考虑到数组的大小是已知的)?对于函数的声明和定义,我都需要帮助。我的想法是这样的:
#include <stdio.h> #define size 10 void function(int anarray[size][size]); //<- Is that correct? ... void function(int anarray[][]) //<-Is this too? { }
非常感谢!
void function1(int anarray[size][size]); // <- Is that correct?
是的。void function1(int anarray[][size]);也可以。
void function1(int anarray[][size]);
void function1(int anarray[][]) // <- Is this too?
不,那是编译器错误。当传递给函数时,只有数组的第一个(最内层)维度会衰减为指针。