Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用For循环更改二维数组中行的值_C++_Arrays_Function_Row - Fatal编程技术网

C++ 使用For循环更改二维数组中行的值

C++ 使用For循环更改二维数组中行的值,c++,arrays,function,row,C++,Arrays,Function,Row,我有一个名为zero\u row的函数。此函数用于将零值插入指定的所有行中。该函数接受多个变量a(数组)和行(数组中的行)。这是我的功能 void zero_row (int a [4][5], int row){ for (int i = 0; i < 4; i++) { a[i][j] = 0; } } void zero_行(int a[4][5],int行){ 对于(int i=0;i

我有一个名为
zero\u row
的函数。此函数用于将零值插入指定的所有行中。该函数接受多个变量
a
(数组)和
(数组中的行)。这是我的功能

void zero_row (int a [4][5], int row){
    for (int i = 0; i < 4; i++) {
        a[i][j] = 0;
    }
}
void zero_行(int a[4][5],int行){
对于(int i=0;i<4;i++){
a[i][j]=0;
}
}
我知道如何将整个数组的值设置为零。因为我也有一个函数来做这件事

void zero_all (int a [4][5]) {
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 5; j++) {
            my_arr[i][j] = 0;
        }
    }
}
void zero_all(int a[4][5]){
对于(int i=0;i<4;i++){
对于(int j=0;j<5;j++){
my_arr[i][j]=0;
}
}
}
我似乎不知道如何使用变量
row
执行此操作。我想使用这个变量,以便以后可以更改主函数中的行,如:
zero\u行(a,3)。有人能帮忙吗


谢谢

在本例中,第一个索引对应一行,第二个索引对应一列

使用

void zero_行(int a[4][5],int行){
对于(int j=0;j<5;j++){//5而不是4
a[行][j]=0;
}
}
void zero_row (int a [4][5], int row){
    for (int j = 0; j < 5; j++) {  // 5 instead of 4
        a[row][j] = 0;
    }
}