Reverse STL end point query

for Reverse function in C++ STL, let us say I want to reverse a row of a 2d array, then why will i write a[i] + n for the end point. (i represents row number)

Should it not be a[i] + n - 1, as the index for nth element is n-1? I know this is not the case but I want to know why.

In fact, when I wrote reverse( a[i], a[i] +1 ), there was no change in the array elements. Why so?

@Samarth_Shah
reverse(s,e) reverses the value from s to e-1 it behaves like [s,e) from s to e not included thats why we have to write 1 greater index
i hope its clear if yes dont forget to hit like and mark resolved :smiley:

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.