函数指针: 一个指向函数的指针。一般用函数名表示。

函数指针数组:元素为函数指针的数组。转移表。c语言中函数不可以定义为数组,只能通过定义函数指针来操作。

 #include<stdio.h>

 //function statement
void func(void);
void func0(void);
void func1(void);
void func2(void);
//defined function pointer array ,& assigned
int(* funcArr[])(void) = { func0,func1,func2 }; int a; int main()
{
func();
printf("main = %p\n",main);
//Function pointer
int(*pfunc)(void) = func;
pfunc(); a = ;
while (a) {
//function pointer array
funcArr[a]();
} system("pause");
return ;
}
//function definition
void func(void) {
printf("hello wworld\n");
return ;
}
void func0() {
printf("function0\n");
a--;
return ;
}
void func1() {
printf("function1\n");
a--;
return ;
}
void func2() {
printf("function2\n");
a--;
return ;
}

注意:

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

参考:

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

04-15 21:17
查看更多