Sorting in descending order

#include
#include
using namespace std;
bool mycompare(int a ,int b){

return a>b;
}

int main(){

int a[]={5,4,3,1,2,6,7};
int n =sizeof(a)/sizeof(int);

sort(a,a+n,mycompare);

for(int i=0; i<n;i++){
cout<<a[i]<<"";
}
return 0;
}
output: 7 6 5 4 3 2 1

how does this code work more specifically what does the mycompare function do in the code ?

Here we go!
The comparison function is a binary function that must return true if the first argument is strictly less than the second. The implementation uses this function to compare two elements of the container to determine which should precede which others - so a and b may be any two elements in your container. This function must give a strict weak ordering over the elements. That is:

An element is never less than itself
If x < y, then it is not the case that y < x
If x < y and y < z, then x < z

My doubt is that why haven’t we passed any arguments in mycompare function inside main function since the prototyping of the function is bool mycompare(int a, int b)

sort is c++ stl
It must be given in its definition.

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.