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
",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
");
33     return 0;
34 }
35 void func0() {
36     printf("function0
");
37     a--;
38     return 0;
39 }
40 void func1() {
41     printf("function1
");
42     a--;
43     return 0;
44 }
45 void func2() {
46     printf("function2
");
47     a--;
48     return 0;
49 }

注意:

 " [ ] "优先级高于“ * ”。

参考:

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

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

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

原文地址:https://www.cnblogs.com/protogenoi/p/9699340.html