   passing 2d arrays into functions
  im trying to add AI to my tictactoe game i want to make a function for my AI i need to pass a 2d array of the game board into it but i dont know how to do it i dont want to pass only 1 array element i want to pass the hole 2d array its self   
  In what language?   ;  If C++ or C, some of the concepts from this thread may help.   ;  c++   ;  do something like this void pass2DArray( int Array2D[][COL])//COL represents some number{//Function definition goes here}When passing 2d array you need to specify the column. So its justlike passing 1d array like this : myFunc(int aray[]), but needs a extrabracket with some number like this myFunc(int array2D[][4]);   ;You could do a typedef to define a type with the fixed subscripts andhaving your gameboard array as this type pass a pointer of that type to the function (or use a & reference param to make it clearer).typedef int MYARRAY[3][3];  // element typw whatever u need for that board slotMYARRAY    gameboard;   // declared in main program scopegameboard[0][0] = whatever;   // access elementsvoid do_something(MYARRAY &localgameboard){if (localgameboard[1][1] == whatever)    {  ...  }   // access elements}   ;Quote:Original post by burgertc++The syntax for passing an array by reference isvoid function(int (&array)[3][3]);But since you are using C++, here is what you should do. Write a class named Board that has this array as a member, and then write member functions that act on that array. No need to pass it around anymore.   