【发布时间】:2020-06-23 06:25:37
【问题描述】:
我试图在函数中传递二维数组,但是有两个我不知道为什么的错误。我有一些关于在函数中传递二维数组的文章,但也无法理解为什么我会失败。
#include <iostream>
using namespace std;
// prototypes
void matrixSwap(double** matrix, int rows, int columns);
int main()
{
const int ROWS = 5;
const int COLUMNS = 5;
double matrix[ROWS][COLUMNS] =
{
{ 1, 2, 3, 4, 5},
{ 6, 7, 8, 9, 0},
{11, 12, 13, 14, 15},
{16, 17, 18, 19, 20},
{21, 22, 23, 24, 25}
};
matrixSwap(matrix, ROWS, COLUMNS);
/* it says
1) argument of type "double (*)[5U]" is incompatible with parameter of type "double **"
2) 'void matrixSwap(double *[],int,int)': cannot convert argument 1 from 'double [5][5]' to 'double *[]'
*/
}
void matrixSwap(double** matrix, int rows, int columns) {}
【问题讨论】:
-
看看这个答案,是同一个问题:stackoverflow.com/a/16724388/13687491
-
这能回答你的问题吗? How to pass a 2D array by pointer in C?