This code is not giving any error. How is it possible to access arr[n]th element?
int main(){
int n;
cin>>n;
int arr[n];
for(int i=1;i<=n;i++){
cin>>arr[i]; // at i=n, it will access arr[n]. How??
}
for(int i=1;i<=n;i++){
cout<<arr[i]<<" ";
}
return 0;
actually it is possible because
int arr[n]; allocates the n contagious memory address starting with arr+0
so when you are taking arr[n] as input you are simply accessing the address arr+n and giving it some value. so when you access it simply prints the value you initialised it with.