1 #include <stdio.h>  
 2   
 3 void PrintNum1(int n);
 4 void PrintNum2(int n);
 5 void ShowNum(int n, void (* ptr)(int));  
 6   
 7 void PrintMessage1();  
 8 void PrintMessage2();  
 9 void PrintMessage3();  
10 void ShowMessage(void (* ptr)());  
11   
12 int main(){  
13    ShowNum(11111, PrintNum1);  
14    ShowNum(22222, PrintNum2);  
15    ShowMessage(PrintMessage1);  
16    ShowMessage(PrintMessage2);  
17    ShowMessage(PrintMessage3);  
18 }  
19   
20 void PrintNum1(int n){  
21    printf("Test1 is called,the number is %dn", n);  
22 }
23 
24 void PrintNum2(int n){  
25    printf("Test2 is called,the number is %dn", n);  
26 }   
27   
28 void ShowNum(int n, void (* ptr)()){  
29    (* ptr)(n);  
30 }  
31   
32   
33 void PrintMessage1(){  
34    printf("This is the message 1!n");  
35 }  
36   
37 void PrintMessage2(){  
38    printf("This is the message 2!n");  
39 }  
40   
41 void PrintMessage3(){  
42    printf("This is the message 3!n");  
43 }  
44   
45 void ShowMessage(void (* ptr)()){  
46     (* ptr)();  
47 }  

 

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!