The following line doesn't work:
int n1=10,v1=10;
int f[n1][v1]={};
error: variable-sized object ‘f’ may not be initialized
But the line below works, why?
const int n1=10,v1=10;
int f[n1][v1]={};
The following line doesn't work:
int n1=10,v1=10;
int f[n1][v1]={};
error: variable-sized object ‘f’ may not be initialized
But the line below works, why?
const int n1=10,v1=10;
int f[n1][v1]={};
Array initializers need to be const.
An int value can change where as a const int value will remain constant throughout the entire program.
In the second example, n1
and v1
are known to be compile-time constants. In the first example, they may not be.