# Passing a row of a Multidemensional Array to a function

• 07-01-2003
skyglin
Passing a row of a Multidemensional Array to a function
Let's say I have 2D array of N rows and M columns, how do pass one of the rows of this array to a function and the function can use this row as a 1D array? Thanks.
• 07-01-2003
quzah
Code:

```void foo( data_type array[SIZE] ) { } ... data_type array[ROWS][SIZE]; foo( array[x] );```
Enjoy.

Quzah.
• 07-01-2003
skyglin
>>>void foo( data_type array[SIZE] )
when defining this function, do I must specify the array size as SIZE (here it corresponds to number of columns) ?
• 07-01-2003
quzah
Passing a row to it is actually passing a pointer to the first element in whatever row. The size specifier was really just for illustration. Consider the following:
Code:

```#include <stdio.h> #define SIZE 10 void foo( char array[] ) {     printf("array is: %s\n", array ); } int main( void ) {     char mdarray[][SIZE] =     {         "foo",         "bar",         "barfoo",         "fweeeeee",         "the end",         0     };     int x;     for( x = 0; mdarray[x][0]; x++ )         foo( array[x] );     return 0; }```
This should run through the list and stop when it hits the null (the zero).

Quzah.
• 03-31-2009
Dave++
confirm multi to one row code?
Way back when...quzah wrote:
Code:

```    for( x = 0; mdarray[x][0]; x++ )         foo( array[x] );     return 0;```
was array[x] supposed to be mdarray[x]?

Regards,
Dave
• 03-31-2009
quzah
Yes. Way to necro a six year old thread!

Quzah.