【发布时间】:2017-10-30 19:41:13
【问题描述】:
我正在尝试弄清楚如何将二维矩阵传递给函数
//function to print Matrix
void refl(int n, int board[][])
{
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
cout << board[i][j] << " ";
}
cout << endl; //printing the matrix to the screen
}
}
int main()
{
int n;
string refl;
cin>>n;
int board[n][n]; //creates a n*n matrix or a 2d array.
for(int i=0; i<n; i++) //This loops on the rows.
{
for(int j=0; j<n; j++) //This loops on the columns
cin>>board[i][j];
refl(n , board);
}
return 0;
}
它说“n”和“board”没有在函数中声明。
【问题讨论】:
标签: c++ arrays function matrix multidimensional-array