Cannot understand how function is passing as a parameter

#include
using namespace std;[quote=“khushmanglani31217_7de9bf16f9c8f286, post:1, topic:167789, full:true”]

#include <iostream>
using namespace std;

bool compare(int a,int b){
     cout<<"Comparing "<<a<<" and "<<b<<endl;
     return a < b;
}

//We will implement our own sort method
void bubble_sort(int arr[],int n, bool (&cmp)(int a,int b)){
     //N-1 iteration to move N-1 large element to the end
     for(int i=0 ; i < n - 1 ; ++i){
          //pairwise swapping in unsorted part
         for(int j=0 ; j < n - i - 1; ++j){
             if(cmp(arr[j+1],arr[j]))
                  swap(arr[j+1],arr[j]);
         }
     }
}

int main(){
    int n;
    cin>>n;

    int a[1000];

    //Taking input from the user
    for(int i=0 ; i < n ; ++i){
         cin>>a[i];
    }

    bubble_sort(a,n,compare);

    for(int i=0 ; i < n ; ++i){
        cout<<a[i]<<",";
    }
   cout<<endl;
   return 0;
}

I am not able to understand how we pass function as parameter void bubble_sort(int arr[],int n, bool (&cmp)(int a,int b)) and how we pass this bool (&cmp)(int a,int b) name to compare function.

hi @khushmanglani31217_7de9bf16f9c8f286 from main function u are passing the name of the function and in the parameters u have to receive the function so for that u need to first write the return type then function name with parameters as done here

Thank you so much for you help

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.