函数指针类型、函数表、接口理论笔记(更新)

函数指针的定义:

void (*point_fun)(const char *str);

point_fun先和*结合是指针,()是函数运算符,所以这个指针是指向函数的


#include <stdio.h>

void say_hello(const char *str);
void (*point_say_hello)(const char *str);//point_say_hello先和*结合是指针,()是函数运算符,所以这个指针是指向函数的

typedef void FUN(const char *str); //定义类一个FUN的函数类型
FUN say_typedef;//用上面定义的类型定义,FUN型的变量,相当于声明一个函数。
FUN *point_say_typedef;//用上面定义的类型定义,FUN型的指针,相当于定义一个函数指针。

void (*say_table[2])(const char *str);//根据运算符的先后顺序可知,say_table是个数组;数组的元素是指针,指向函数的指针。
//void (*say_table[2])(const char *str) = {point_say_hello, point_say_typedef};
#define say_interface(a) say_table[a]("lang")//相当于接口 

typedef void (*POINT_FUN)(const char *str); //定义类一个POINT_FUN的函数指针类型
POINT_FUN point_fun	;

void main(){
	printf("lang start \n");
	point_say_hello = say_hello;
	point_say_hello("langxw");

	point_say_typedef = say_typedef;
	point_say_typedef("langxw");

	say_table[0] = point_say_hello;
	say_table[1] = point_say_typedef;
	say_interface(0);
	say_interface(1);
	
	point_fun = say_hello;
	point_fun("point_fun");
}

void say_hello(const char *str){
	printf("hello %s \n", str);
}

void say_typedef(const char *str){
	printf("typedef %s \n", str);
}



end



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值