c語言.函數指針數組

函數指針: 一個指向函數的指針。通常用函數名錶示。數組

函數指針數組:元素爲函數指針的數組。轉移表。c語言中函數不能夠定義爲數組,只能經過定義函數指針來操做。函數

 1 #include<stdio.h>
 2 
 3 //function statement
 4 void func(void);  5 void func0(void);  6 void func1(void);  7 void func2(void);  8 //defined function pointer array ,& assigned
 9 int(* funcArr[])(void) = { func0,func1,func2 }; 10 
11 int a; 12 
13 int main() 14 { 15  func(); 16     printf("main = %p\n",main); 17     //Function pointer
18     int(*pfunc)(void) = func; 19  pfunc(); 20 
21     a = 2; 22     while (a) { 23         //function pointer array
24  funcArr[a](); 25  } 26     
27     system("pause"); 28     return 0; 29 } 30 //function definition
31 void func(void) { 32     printf("hello wworld\n"); 33     return 0; 34 } 35 void func0() { 36     printf("function0\n"); 37     a--; 38     return 0; 39 } 40 void func1() { 41     printf("function1\n"); 42     a--; 43     return 0; 44 } 45 void func2() { 46     printf("function2\n"); 47     a--; 48     return 0; 49 }

注意:spa

 " [ ] "優先級高於「 * 」。.net

 

參考:指針

https://blog.csdn.net/u010925447/article/details/74295692code

https://blog.csdn.net/qq_29924041/article/details/53933104blog

https://blog.csdn.net/u014265347/article/details/54882661it

相關文章
相關標籤/搜索