while I was going  through stl today, I came across a situation where to sort my dynamically allocated array from arr[0],,..arr[n-1]. I was using command 
#include<algorithm>
.
.
int *arr = new int[n]();
//loop to take user input for each arr[i]
sort(&arr[0],&arr[n]) 
The above command was sorting the array without any error, even if I have allocated memory up to arr[n-1].
The below command was sorting upto n-1th element.
#include<algorithm>
.
.
int *arr = new int[n]();
//loop to take user input for each arr[i]
sort(&arr[0],&arr[n-1]) 
How was '&arr[n]' working in the 1st code snippet.
 
     
     
    