c - 将多维数组作为参数传递给c

标签 c function multidimensional-array arguments argument-passing

基本上,我要做的是将数组作为参数传递。我想到了这样的想法:

#include <stdio.h>
#include <stdlib.h>

int x;

void function(int array[][x]){
    //stuff here
}

int main(){
    x = random(10);
    int array[10][x];
    //initialize array
    function(array[10][x]);
}

我认为这应该可行,但它给了我一个注释:

expected ‘int (*)[(unsigned int)(x)]’ but argument is of type ‘int’

如有任何帮助,我们将不胜感激。

最佳答案

使用

function(array)

代替

function(array[10][x])

您可能想阅读 this post我前几天做了。

关于c - 将多维数组作为参数传递给c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13745375/

相关文章:

c++ - PCRE中的匹配顺序

php - jQuery/Ajax 获取 html 并用 php 保存

javascript - HTML javascript 函数

php - 多维数组

c - 为什么我在多维数组中不断收到消息 "Error: arr parameter is initialized."?

java - 从二维数组中顺序接收元素(Java)

c - 传递到内核的值变得困惑

c - 尝试编写字节序检测程序,但无法比较 char 值

c - Malloc 使先前分配的指针无效?

function - 按要求次数执行功能