c - 我在 C 中的数组的函数调用中遇到错误?
问题描述
使用数组在 C 中进行函数调用时出现意外错误,我对 C 有一点了解,但不明白如何修复它。下面附上main函数的代码。
void sum_matrices (int m1[][NUM_COLS], int m2[][NUM_COLS], int num_rows, int result[][NUM_COLS]);
void print_matrix (int m[][NUM_COLS], int num_rows);
void print_array (int a[], int len);
int main(void) {
int my_matrix_1[][NUM_COLS] = {{1, 5, 3, 4, 2},
{7, 1, 4, 1, 7},
{6, 9, 2, 0, 5}};
int my_matrix_2[][NUM_COLS] = {{7, 8, 3, 3, 4},
{1, 3, 7, 8, 2},
{1, 3, 5, 6, 0}};
int num_rows = 3;
int result[num_rows][NUM_COLS]; // finish this line of code to create the result matrix to pass to sum_matrices
// add call to sum_matrices to add my_matrix_1 and my_matrix_2
sum_matrices (my_matrix_1[][NUM_COLS], my_matrix_2[][NUM_COLS], num_rows, result[][NUM_COLS]);
print_matrix(my_matrix_1, num_rows);
printf("\n");
print_matrix(my_matrix_2, num_rows);
printf("\n");
print_matrix(result, num_rows);
return 0;
}
解决方案
sum_matrices
您在函数中对函数的“调用” main
...
sum_matrices (my_matrix_1[][NUM_COLS], my_matrix_2[][NUM_COLS], num_rows, result[][NUM_COLS]);
是函数的前向声明和函数调用的混合,但两者都不完整,也不允许在该形式的该位置。
要调用该函数,请编写...
sum_matrices (my_matrix_1, my_matrix_2, num_rows, result);
推荐阅读
- javascript - 条件运算符未正确评估
- matplotlib - 减少 matplotlib 和 seaborn 中刻度标签的数量
- python - 是否有任何解决方案可以使用我自己的后端向现有用户添加社交资料?
- nginx - nginx为子目录设置反向代理,页面为空白
- emacs - 如何自定义 org-agenda 时钟表的深度?
- c# - 如何最小化排序运行时的复杂性?
- c# - OpenTK 从 dds 纹理手动上传 mipmap 不起作用
- alias - 在命令的建议中启用别名展开
- python - 如何使用 lxml 将命名空间 URI 转换为前缀?
- javascript - 将控制台日志结果打印到 div 类的多个实例