how to pass a two-dimension array to a function in C++??

S

ssss

I need pass a double-type two-dimension array to a function, I can not
figure out,please help.
 
R

Robert Gamble

I need pass a double-type two-dimension array to a function, I can not
figure out,please help.

This group discusses Standard C, not C++, hence the name comp.lang.c.
Please ask your question in comp.lang.c++.

Rob Gamble
 
J

Jens.Toerring

ssss said:
I need pass a double-type two-dimension array to a function, I can not
figure out,please help.

#include <stdio.h>
#include <stdlib.h>

#define ROWS 31
#define COLUMNS 42

void gets_passed_2d_array( double x[ ][ COLUMNS ],
size_t nrows, size_t ncols );

int main( void )
{
double a[ ROWS ][ COLUMNS ];
size_t i, j;

for ( i = 0; i < ROWS; i++ )
for ( j = 0; j < COLUMNS; j++ )
a[ i ][ j ] = i * COLUMNS + j;

gets_passed_2d_array( a, ROWS, COLUMNS );
return EXIT_SUCCESS;
}

void gets_passed_2d_array( double x[ ][ COLUMNS ],
size_t nrows, size_t ncols )
{
size_t i, j;

for ( i = 0; i < nrows; i++ )
for ( j = 0; j < ncols; j++ )
printf( "x[ %lu ][ %lu ] = %f\n", ( unsigned long ) i,
( unsigned long ) j, x[ i ][ j ] );
}

Or what exactly are you looking for?
Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top