orders two arguments using pointers : function pointers « Function « C++ Tutorial






#include <iostream>  
  using namespace std;  
    
  int main(){  
     void order(int*, int*); 
    
     int n1=99, n2=11;       
     int n3=22, n4=88;  
    
     order(&n1, &n2);        
     order(&n3, &n4);  
    
     cout << "n1=" << n1 << endl;  
     cout << "n2=" << n2 << endl;  
     cout << "n3=" << n3 << endl;  
     cout << "n4=" << n4 << endl;  
     return 0;  
    }  

  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