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?
Printable View
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?
try passig it as def[subscript1][subscript2]
if you know them in advance
otherwise use
int** def
You have to specify the first index:
bool abc(int def[10][]);
jasrajva(anybody), can you please given me an example of
int** def
specifying the first index would really limit the functionality.
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.
Try this m8, this is a small example of how it is done
#include <iostream.h>
void read(int a[][5]);
void print(const int a[][5]);
int main()
{
int a[3][5];
read (a);
print(a);
return 0;
}
void read(int a[][5])
{
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;
}
}