I just wanted to know–is this the correct way to pass a pointer to a 2-D Array by reference in a function?
bool test::testTheNumber(test (*arr)[9][9], int testNumber, int row, int column)
{
if(theRow(arr, testNumber, row) && theColumn(arr, testNumber, column))
....
}
My “theRow” and “theColumn” answers are very similar to the test function:
bool sodoku::theRow(sodoku (*arr)[9][9], int testNumber, int row)
bool sodoku::theColumn(sodoku (*arr)[9][9], int testNumber, int column)
In my main.cpp, I have a pointer to a 2d array and I called my functions like this:
test *arr[9][9];
theRow(arr,0,0);
theColumn(arr,0,0);
testTheNumber(arr,0,0,0,0);
Would the array pass by reference or would I have to use a & instead of a *? I am just a little confused as I’m not entirely sure how 2-D arrays would work.
Thanks.
This
Or
The first dimension in the array isn’t needed.
Really, arrays are passed by reference by default. You don’t need a
&.For more information, you may want to read this answer to this question.