The main advantage of function pointer is that it allows us to pass functions as arguments to other functions. For example:

using ForeachCb = int (*)(int);
 
void foreach (int *start, int *end, ForeachCb cb)
{
    for (; start != end; ++start)
    {
        std::cout << cb(*start) << '\n';
    }
}
 
int _double(int v)
{
    return v * 2;
}
 
int is_even(int v)
{
    return v % 2 == 0;
}
 
int main(int argc, char const *argv[])
{
    std::array arr{1, 2, 3, 4, 5};
 
    foreach(arr.begin(), arr.end(), _double);
    foreach(arr.begin(), arr.end(), is_even);
 
    return 0;
}

References

  1. https://www.learncpp.com/cpp-tutorial/function-pointers/