I have this code:
int m, n;
cin>>m>>n;
double A[m][n];
//read values for A
How can I pass A to a function?
Variable length arrays are a C feature and not supported in standard C++. However some compilers such as gcc support it as an extension.
On those compilers that do support it, you would need to pass the array dimensions as parameters and use those parameters as the array size:
void handle_array(int m, int n, double A[m][n])
{
...
}
Note that this is only required for a multidimensional array, and not for the first dimension. You could also pass it as follows:
void handle_array(int m, int n, double A[][n])
{
...
}
Or equivalently:
void handle_array(int m, int n, double (*A)[n])
{
...
}
m is the only dimension that needs to be passed in separately, and that n must be specified when writing the array parameter but not m. More importantly, it leaves out a more idiomatic C++ approach that doesn't rely on a compiler extension.