The first thing you have to look after is that dasblinkenlight has already mentioned in his answer, variable-length arrays are a language extension.
Then you should think that arrays are zero index based. What does this means? Let's consider an array of size 4 that is denoted as arr. Then it's elements can be accessed as arr[0], arr[1], arr[2], and arr[3]. So what happens when you run your first loop?
for(int i = 1; i<= N; i++) {
cin >> arr[i];
}
You set the a value for arr[1], arr[2] to arr[N]. But the arr[N] points to a place in memory that is not associated with the array, since the array's size is N and all arrays are zero based. The last element of the array lives in here arr[n-1].
Unfortunately in C++ there isn't any check for the length of an array and you are allowed to do things like this. For instance, if you had tried this in C# or in Java then you would have got an Index Out Of Range Exception.
If you change your code to the following, then you will get the expected output:
for(int i = 0; i<N; i++) {
cin >> arr[i];
}
for(int i = 0; i<N; i++) {
cout << arr[i] << endl;
}
std::vectorinstead.std::vectorinstead. Usingstd::vectornot only makes your program standard C++, you have the chance to check your own errors like this usingat().