Array question
is there a short hand way of passing just a row in a 2d array into a function that accepts only 1d arrays. for example something like this even though I know that this doesn't work. I don't want to have to use loops to copy a row from the 2d array into a 1d array and then pass the 1d array into the function foo.
function foo(int array[4]) {
do something
}
int main() {
int test[2][4] = {{1,2,3,4},{5,6,7,8}};
// pass only 1,2,3,4 into the function
foo(test[0][]);
}
Talguy
Junior Poster in Training
96 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
when passing the row from a 2D array to a function that takes a 1D parameter, use only the row index in your argument.
foo( test[0] );
That essentially passes a pointer to where that row begins.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Thanks vmanes, thats exactly how I needed to do it.
Talguy
Junior Poster in Training
96 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0