Array declaration in C/C++ will not be success if you don't provide a constant size. For the beginners who do not familiar with pointers the following may give a good understanding.
1. Declare an array with a maximum size; when your input exceeds this limit you can always show an error message.
int x[100];
2. when you deal with an array size within the maximum size, keep the dynamic size in a variable and use the variable as the size of your array instead of the maximum size.
int main(){
int x[100]; int size;
cin>>size; if (size>=100){
cout<<"Array size exceeds the maximum allocation";
return 0;
}
for(int i=0; i<size; i++){
cin>>x[i];
}
for(int i=0; i<size; i++){
cout<<x[i]<<endl;
}
return 0;
}
Hope this will help.