测试平台:64位X86Ubuntu
1. 代码:
#include <stdio.h>int print(int a){printf("a = %d\n", a);}void main(void){int (*pf)(int);int (*pf1)(int);pf = print;pf1 = &print;print(1);pf(2);pf1(3);(*pf)(4);(*pf1)(5); }
2. 编译
无警告,无错误
3. 结果:
baoli@ubuntu:~/c$ ./a.out
a = 1
a = 2
a = 3
a = 4
a = 5
4. 分析:
1)函数指针的赋值有两种形式
2)函数指针的运行也有两种形式