C语言 函数指针一(函数指针的定义)

时间:2023-03-09 15:26:37
C语言 函数指针一(函数指针的定义)
//函数指针
#include<stdio.h>
#include<stdlib.h>
#include<string.h> //函数指针类型跟数组类型非常相似 //函数名就是函数的地址,函数的指针,对函数名进行&取地址操作,还是函数名本身,这是C语言编译器的特殊处理
void test(int a){
printf("a=%d\n",a);
} void ProtectA(){
//定义函数类型
typedef void(FunType)(int);
FunType *ft = test;
FunType *ft2 = &test;
//这两种赋值方式的结果完全一样
ft();
ft2(); //定义函数指针类型
typedef void(*PFun)(int);
PFun pf = test;
pf(); //定义函数指针变量
void(*pf2)(int) = test;
pf2();
} void main(){
ProtectA();
system("pause");
}

C语言 函数指针一(函数指针的定义)