Help getting error on REVMEE (reverse a list of int)

using namespace std;

int main() {
int n;
int arr[n];
cin>>n;
for(int i=1;i<=n;i++){
    cin>>arr[n-i];
}
for(int i=0;i<n;i++){
    cout<<arr[i]<<" ";
}
return 0;
}```

your are getting error because you
array size is not initialize

first read input for n
cin>>n;

then initialize

int arr[n];

1 Like

Another case where just looking at compiler warnings would reveal the issue :slight_smile:

[simon@simon-laptop][14:35:15]
[~/devel/hackerrank/otherpeoples]>g++ -std=c++14 ninja_69o-REVMEE.cpp -O3 -g3 -Wall -Wextra -Wconversion 
ninja_69o-REVMEE.cpp: In function ‘int main()’:
ninja_69o-REVMEE.cpp:7:14: warning: ‘n’ is used uninitialized in this function [-Wuninitialized]
     int arr[n];
              ^
1 Like

Ah I see , accutually it was giving me correct output on compiler and error on submission , that’s why I got confused .kekw thanks

Oops, thanks