如何将二维数组作为函数的参数传递(认为数组的大小已知)?我将需要帮助声明和函数的定义.我的想法是这样的:
#include <stdio.h>
#define size 10
void function(int anarray[size][size]); //<- Is that correct?
...
void function(int anarray[][]) //<-Is this too?
{
}
Run Code Online (Sandbox Code Playgroud)
非常感谢!
小智 6
void function1(int anarray[size][size]); // <- Is that correct?
Run Code Online (Sandbox Code Playgroud)
是的.void function1(int anarray[][size]);会工作的.
void function1(int anarray[][]) // <- Is this too?
Run Code Online (Sandbox Code Playgroud)
不,那是编译器错误.传递给函数时,只有数组的第一个(最里面的)维度衰减成指针.
| 归档时间: |
|
| 查看次数: |
4621 次 |
| 最近记录: |