用c语言打印多维数组

用c语言打印多维数组,c,arrays,function,multidimensional-array,C,Arrays,Function,Multidimensional Array,我试图打印具有特定维度的数组,但它在运行时打印出错误的实体 //code #include <stdio.h> int my_array[2] [4] = { {1, 2, 3, 4}, {5, 6, 7, 8} }; void print_array(const int h, const int w, char array[][w]) { int nRow = h; int nColumn = w; for(int i = 0; i < nRow; i+

我试图打印具有特定维度的数组,但它在运行时打印出错误的实体

//code
#include <stdio.h>

int my_array[2] [4] = {
{1, 2, 3, 4}, {5, 6, 7, 8}
};

void print_array(const int h, const int w, char array[][w]) {
   int nRow = h;
   int nColumn = w;
   for(int i = 0; i < nRow; i++)  {
        printf("--- Row %d --- \n", i);
        for(int j = 0; j < nColumn; j++) {
            printf("Column [%d] = %d \n", j, array[i] [j]);
        }
   }
}

int main(int argc, char **argv)
{
    const int array_width = 4;
    const int array_height = 2;
    print_array(array_height, array_width, my_array);
    return 0;
}
//代码
#包括
int my_数组[2][4]={
{1, 2, 3, 4}, {5, 6, 7, 8}
};
无效打印数组(常量整数h、常量整数w、字符数组[][w]){
int nRow=h;
int nColumn=w;
对于(int i=0;i
编译后,它会打印出下一个结果:


在函数
print\u array
中将
字符数组[][w]
更改为
int array[][w]
,该函数需要整数数组。编译器可能会发出不兼容的类型警告,但这很容易错过!尝试编译没有警告的程序。

char array[][w]
应该是
int array[][w]
@BarmakShemirani,并且应该作为一个答案发布。然后,它给了你一些警告,你应该更正你的代码以避免警告。@spongebsquarepants微软不允许从控制台复制文本吗?您的输出应该作为文本包含,而不是作为文本的屏幕截图,其中文本是相对不可读的5pt。@BarmakShemirani“延伸”到一个答案并不难。将该行复制到下面的编辑字段中。使用一些换行符进行格式化。然后做一个小文本,以“这行…”开头,继续以“因为…”开头。提及不同大小的
char
int
并猜测它们是什么。这个问题不是世界级的,但也不是离题的。因此,你甚至应该避免被“离题问题的好答案就是坏答案”一族的人投下反对票。