Can anyone please explain how it works?
We are not calling sortbysec as function, but still I got the right answer.  Why there is no need to pass the pair in sortbysec?
Please explain, as I am confused about internal workings of std::sort function.
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.second == b.second)
        return (a.first < b.first);
    else
        return (a.second < b.second);
}
sort(v.begin(), v.end(), sortbysec);
 
    