Why u use sort(a, a+n, compare)

why a+n is used sir…

@rajan_s
Sort() function need beginning address and ending address of array which need to be sorted.
a is starting address whereas (a+n) is the ending address of the array a. That’s why we use sort(a,a+n,compare);

You want to sort n elements of the array a. How do you think you think that the sort function is going to know what all elements are to be sorted? It’s the first and second arguments that you pass that lets the function know about the range of elements to be sorted.

the first argument that you pass to the sort function is a random access iterator pointing to the beginning and the second argument is a random access iterator pointing to the end of array that you want to sort