相关疑难解决方法(0)

C:用于交换2D数组中的值的函数

我正在尝试编写一个函数来交换2D数组中的2个元素:

void swap(int surface[][], int x1, int y1, int x2, int y2) {
    int temp = surface[x1][y1];
    surface[x1][y1] = surface[x2][y2];
    surface[x2][y2] = temp;
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试编译它(gcc)时,我收到此错误消息:

Sim_Annealing.c: In function `swap': 
Sim_Annealing.c:7: error: invalid use of array with unspecified bounds
Sim_Annealing.c:8: error: invalid use of array with unspecified bounds
Sim_Annealing.c:8: error: invalid use of array with unspecified bounds
Sim_Annealing.c:9: error: invalid use of array with unspecified bounds
Run Code Online (Sandbox Code Playgroud)

为了将2D数组作为函数参数,我是否需要做一些特殊的魔术?

谢谢你的帮助.如果你知道有关数组的任何好的引用作为函数参数发送我的方式:)

c arrays function-parameter

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

arrays ×1

c ×1

function-parameter ×1