sorts an array using pointers : function pointers « Function « C++ Tutorial






#include <iostream>  
  using namespace std;  
    
  int main(){  
     void bsort(int*, int);    
     const int N = 10;         
     int arr[N] = { 37, 84, 62, 91, 11, 65, 57, 28, 19, 49 };  
    
     bsort(arr, N);  
    
     for(int j=0; j<N; j++)  
        cout << arr[j] << " ";  
     cout << endl;  
     return 0;  
    }  
  void bsort(int* ptr, int n){  
     void order(int*, int*); 
     int j, k;               
    
     for(j=0; j<n-1; j++)    
        for(k=j+1; k<n; k++) 
           order(ptr+j, ptr+k);
    }  
  void order(int* numb1, int* numb2){  
     if(*numb1 > *numb2){  
        int temp = *numb1;
        *numb1 = *numb2;  
        *numb2 = temp;  
     }  
  }








7.10.function pointers
7.10.1.Using function pointers
7.10.2.Arrays of pointers to functions
7.10.3.Use function pointers as a function parameter
7.10.4.Use typedef to define a function type for function pointer
7.10.5.arguments passed by reference
7.10.6.arguments passed by pointer
7.10.7.array passed by pointer
7.10.8.orders two arguments using pointers
7.10.9.sorts an array using pointers
7.10.10.Function pointer for overloaded function