【发布时间】:2017-12-24 13:33:04
【问题描述】:
我正在尝试编写一个将数组初始化为零的函数:
void InitializingToZero(int numOfrows, int numOfcols, int array[][20]) {
for (int i = 0; i < numOfrows; i++) {
for (int j = 0; j < numOfcols; j++) {
array[i][j] = 0;
}
}
}
int main() {
int num_of_rows = 3;
int num_of_cols = 3;
int array[num_of_rows][num_of_cols];
InitializingToZero(num_of_rows, num_of_cols, array);
for (int i = 0; i < num_of_rows; i++) {
for (int j = 0; j < num_of_cols; j++) {
printf("%d ", array[i][j]);
}
printf("\n");
}
}
我得到这个输出:
0 0 0
0 0 0
268501009 0 4200656
【问题讨论】:
标签: c arrays function multidimensional-array