If n is taken as input at runtime then how are we able to create an array with n elements at compile time? I understand that it will run perfectly fine in input[] case but am I not getting any error for input2?
I tried following code and it works fine:
int main(){
int n;
cin >> n;
int *input = new int[n];
for(int i=0;i<n;i++)
input[i] = i;
for(int i=0;i<n;i++)
cout<<input[i]<<" ";
cout<<endl;
int input2[n];
cout<<n<<endl;
for(int i=0;i<n;i++)
input2[i] = i;
for(int i=0;i<n;i++)
cout<<input2[i]<<" ";
}