From C++ document http://www.cplusplus.com/doc/tutorial/arrays/
To define an array like this int a[b]; the variable b must be a constant.
Here is what I am running under g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
int main(){
int a = 10;
int b[a];
for(int i = 0; i < 10; i++){
cout << b[i] << endl;
}
return 0;
}
variable a is not a constant and I have no error. May I ask start from what version of g++ will accept this kind of array definition?
aout so that you are, in fact, initializing with a constant. Try instead initializing withrand()/100000and see what happens (#include <cstdlib>)