Gavin Youker - 1 year ago 43

C++ Question

I have a function called

`zero_row`

`a`

`row`

`void zero_row (int a [4][5], int row){`

for (int i = 0; i < 4; i++) {

a[i][j] = 0;

}

}

I know how to set values of the entire array to zero. As i have a function to do this as well.

`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;

}

}

}

I cant seem to figure out how to do this using the variable

`row`

`zero_row(a, 3);`

Thanks!

Answer Source

In your case the first index corresponds to a row and the second index corresponds to a column.

Use

```
void zero_row (int a [4][5], int row){
for (int j = 0; j < 5; j++) { // 5 instead of 4
a[row][j] = 0;
}
}
```