# how can i pass 2d arrays

• 11-01-2001
Unregistered
how can i pass 2d arrays
i am trying to define function to accept 2d arrays like this

bool abc(int def[][]);

but vc is not letting me, with this error

error C2087: '<Unknown>' : missing subscript

does this means we can't pass 2d arrays?
• 11-01-2001
jasrajva
try passig it as def[subscript1][subscript2]
if you know them in advance
otherwise use
int** def
• 11-01-2001
Troll_King
You have to specify the first index:

bool abc(int def[10][]);
• 11-01-2001
Unregistered
jasrajva(anybody), can you please given me an example of

int** def

specifying the first index would really limit the functionality.
• 11-02-2001
Salem
Marvellous - 3 wrong answers in a row - at least Troll_King is on the right track.

If you have
int array[ROW][COL];

Then the valid function prototypes are
void foo ( int a[ROW][COL] );
void foo ( int a[][COL] );
void foo ( int (*a)[COL] );

And you call this function like so
foo ( array );

You must specify all the substripts - EXCEPT the first one, which is entirely optional.
• 11-02-2001
frgmstr
Try this m8, this is a small example of how it is done

#include <iostream.h>

void print(const int a[][5]);

int main()
{
int a[3][5];
print(a);

return 0;
}

{

cout << "Enter 15 integres, 5 per row:\n";
for(int i = 0; i < 3; i++)
{
cout << "Row " << i << ": ";
for(int j = 0; j < 5; j++)
cin >> a[i][j];
}
}

void print(const int a[][5])
{

for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 5; j++)
cout << " " << a[i][j];
cout << endl;

}

}