May 4, 2011 at 7:16pm UTC
how to pass 2D array to a function ?
e.g:
void twoDim(int values[][],int size)
{
for(int i=0; i<9; i++)
{
for(int j=0; j<9; j++)
{
cout << Nums[i][j] <<" ";
}
cout << endl;
}
}
......... .................................
Is the heading correct ?
and how to call this function ?
May 4, 2011 at 8:27pm UTC
thats fine except that for the for the last dimension there you need to specify the size. to call the function you would do something like this
1 2 3
int values[2][2] = { { 0, 1 }, { 2, 3 } };
int size = sizeof (values)/sizeof (values[0][0]);
twoDim(values, size);
please use code tags in the future by clicking the < > sign under format.
Last edited on May 5, 2011 at 1:57am UTC
May 5, 2011 at 1:44am UTC
Sorry, OK I will next time :>
.................................................
how to solve these errors ?
error C2087: 'values' : missing subscript (in the heading of the void function)
error C2664: 'twoDi' : cannot convert parameter 1 from 'int [9][9]' to 'int [][1]' (in the calling function in main)
??
.....
Last edited on May 5, 2011 at 1:47am UTC
May 5, 2011 at 1:50am UTC
any dimensions beyond the first, have to be explicitly defined in a function header, so
void twoDim(int values[][9],int size)