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 }

注意:

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

 

参考:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值