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?
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
jv
You have to specify the first index:
bool abc(int def[10][]);
Last edited by Troll_King; 11-01-2001 at 08:30 PM.
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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;
}
}