gpt4 book ai didi

c - 在非递归数组中填充多行的不寻常方法?

转载 作者:太空宇宙 更新时间:2023-11-04 08:31:55 26 4
gpt4 key购买 nike

您好,我正在调试 C 应用程序并在 10 行 4 列的数组中看到这种奇怪的行为:

void fillArray(int *B){ 
//DEBUG
printArray(B,10,4);//printing all items 0's
B[3,0] = 3;
printArray(B,10,4); // results in B[0,0] = 3 , B[1,0] = 3 , B[2,0] = 3 , B[3,0]= 3 , ...
// Rest values remains zero.
}



void printArray(int *B,int imax,int jmax){
printf(" \n --- Check---");

for(i=0;i<imax;i++){
for(j=0;j<jmax;j++){
printf(" \n Check: B[%d,%d]=%d ",i,j,B[i,j]);
}
}
}

为什么值 3 插入到表的每一行中的第 0 列?

最佳答案

您正在使用表达式 3, 0 来索引数组。该表达式的值为 0(它使用序列运算符,其值是最后一个表达式的值,在本例中为常量 0)。要在 C 中索引多维数组,您需要使用类似 m[a][b] 的东西。

关于c - 在非递归数组中填充多行的不寻常方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27943724/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com