函式型別,函式名是函式指標嗎,函式的強制型別轉換
阿新 • • 發佈:2019-02-06
2
3 typedef int (*funcptr)();
4
5 int func_ptr1(){
6 printf("func_ptr1 is called!\n");
7 return 1;
8 }
9
10 void func_ptr2(int a){
11 printf("func_ptr2 is called!\n");
12 }
13 int main(){
14 int a;
15 char b='a';
16 a=(int)b;
17 b=(char)a;
18 funcptr func1, func2;
19 int (*fun1)(), (*fun2)();
20 func1 = fun1 = func_ptr1;
21 fun2 = (int (*)(int))func_ptr2;
22 func2 = fun2;
23 printf("================\n");
24 (*fun1)();
25 (*fun2)();
26 printf("================\n");
27 (*func1)();
28 (*func2)();
29
30 }
3 typedef int (*funcptr)();
4
5 int func_ptr1(){
6 printf("func_ptr1 is called!\n");
7 return 1;
8 }
9
10 void func_ptr2(int a){
11 printf("func_ptr2 is called!\n");
12 }
13 int main(){
14 int a;
15 char b='a';
16 a=(int)b;
17 b=(char)a;
18 funcptr func1, func2;
19 int (*fun1)(), (*fun2)();
20 func1 = fun1 = func_ptr1;
21 fun2 = (int (*)(int))func_ptr2;
22 func2 = fun2;
23 printf("================\n");
24 (*fun1)();
25 (*fun2)();
26 printf("================\n");
27 (*func1)();
28 (*func2)();
29
30 }