C ++将多维数组传递给函数

时间:2014-10-08 19:17:40

标签: c++

所以我必须使用3x3阵列为我的课程编写这个Tic Tac Toe程序。

我用

声明了数组
char board[3][3] =
{
    {'1', '2', '3'},
    {'4', '5', '6'},
    {'7', '8', '9'}
};

但是说我需要将数组传递给一个函数,该函数在tic tac toe board上打印出数组的所有元素。

///
/// <> This function prints the grid utilized for Tic Tac Toe in an easy-to-read manner
///
void printGrid (char& ticTacToeBoard)
{
    cout << "   1   2   3   " << endl
     << " 1  " << ticTacToeBoard[0][0] << " | " << ticTacToeBoard[0][1] << " | "   <<ticTacToeBoard[0][2] << endl
     << "   " << "___|___|___"
     << " 2  " << ticTacToeBoard[1][0] << " | " << ticTacToeBoard[1][1] << " | " << ticTacToeBoard[1][2] << endl
     << "   " << "___|___|___"
     << " 3  " << ticTacToeBoard[2][0] << " | " << ticTacToeBoard[2][1] << " | " << ticTacToeBoard[2][2] << endl;

您如何将多维数组传递到所述函数中,以便它知道这些板数组值是什么?

我对编程非常陌生,并且非常努力学习这门课程,所以请尽量不要过多详细说明!

0 个答案:

没有答案