Suppose I have this code:
Code:
#include <iostream>
void foo(int a[][3]);
int main()
{
int num[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
//size of array calculated in here
foo(num);
std::cin.get();
}
void foo(int a[][3])
{
std::cout<<a[2][1];
return;
}
What if I don't know that the number of columns is going to be 3 for the two dimensional array? I just know in the function prototype that I need to receive a two dimensional array and I have another variable that will be used for the size of the array? So it would look more like this:
Code:
#include <iostream>
void foo(int a[][], int size);
int main()
{
int num[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
//size calculated in here
foo(num);
std::cin.get();
}
void foo(int a[][], int size)
{
std::cout<<a[2][1];
return;
}
I have a program where the size of the puzzle is determined by another file (crossword puzzle) so the program isn't very generic when everytime I want to do another puzzle I have to hard code what the size of the puzzle will be in the function prototype/function definition when it can be easily calculated from the files. Thanks.