Why this dont work:
int size = 2;
int array[size];
int main() {
return 0;
}
It says the error: array bound is not an integer constant
And this work:
int size = 2;
int main() {
int array[size];
return 0;
}
Anyone knows the reason?
thanks
In C++ or C89/90 neither works. These languages require that array size is an Integral Constant Expression (ICE). In your examples
sizeis not an ICE. If your C++ or C89/90 compiler allows it, it is nothing else than a non-standard compiler extension.In C99 the second works because this is how Variable Array Length (VLA) specification is defined. VLA can only be defined in local scope.