I am trying to initialise a 2d-array to 0 in C of size m x n which are inputs in my function. Here is an example (not interested in the output hence void type):
void createArray(int m, int n)
{
int array[m][n]={0};
}
I get the error: "Variable-sized object may not be initialized". I had no luck when I used "const int" instead of "int" also.
This works fine if I don't try to assign 0 to the array:
void createArray(int m, int n)
{
int array[m][n];
}
Is there a way around this? It seems inefficient to have to loop over the array setting all values to 0, but maybe this is how C initialises it anyway?