Is it possible to pass a pointer to an operator as an argument like a pointer to a function?

You cannot obtain a pointer to a built-in operator. But fortunately, the standard library provides function objects for all standard operators. In your case, that object's name is std::greater:

sort (arr, arr + N, std::greater<int>{});

Since C++14, you can even omit the argument type and it will be deduced from how the object is used:

sort (arr, arr + N, std::greater<>{});

And since C++17, the empty <> can be omitted too:

sort (arr, arr + N, std::greater{});

You cannot do that, but you can use a lambda directly inside the sort, or store the lambda itself in a variable if you need to pass the comparator around

sort (arr, arr + N, [](int a, int b){ return a > b; });

or

auto comp = [](int a, int b){ return a > b; };
sort (arr, arr + N, comp);

or as suggested you can use the std::greater

sort (arr, arr + N, std::greater<>{});

Tags:

C++