当前位置: 首页 > news >正文

函数指针和指针函数

1.函数指针

不说废话,函数指针格式

指针类型 (*指针名)(参数1, 参数2, ......)

比如

#include <stdio.h>
void fun1(int a) {printf("a is %d. this funtion is fun1",a);
}
void fun2(int b) {printf("b is %d. this funtion is fun2",b);
}
void fun3(int c) {printf("c is %d. this funtion is fun3",c);
}
void (*point)(int);
int main() {point = fun2;point(3);
}

输出

the b is 3. this funtion is fun2

2.指针函数

指针函数格式

函数类型 (*指针名)(参数1, 参数2, ......)

比如

#include <stdio.h>
void fun1(int a) {printf("a is %d. this funtion is fun1",a);
}
void fun2(int b) {printf("b is %d. this funtion is fun2",b);
}
void fun3(int c) {printf("c is %d. this funtion is fun3",c);
}
void (*point())(int) {return fun1;
}
int main() {void(*point2)(int) = point();point2(5);
}

输出

a is 5. this funtion is fun1


http://www.mrgr.cn/news/54575.html

相关文章:

  • Qt5.14.2 安装详细教程(图文版)
  • 反弹Shell
  • 【OpenCV】人脸识别方法
  • 学习eNSP对提升就业竞争力有多大帮助?
  • 【JavaEE初阶】深入理解TCP协议中的封装分用以及UDP和TCP在网络编程的区别
  • java计算两个日期之间相差几天(小时、天)小时计算
  • 一套开源轻量级的新零售快消进销存管理系统,使用.Net7 + Angular4开发(附私活源码)
  • 腾讯云技术深度解析:构建高效云原生应用与数据安全管理
  • 爬虫+数据保存
  • Maven 的使用:在 IDEA 中配置 Maven 的超详细步骤
  • centOS部署Jenkins实现项目可持续自动化部署
  • LLM | Hugging Face | 如何利用几句代码实现强大的AI效果(pipeline)?
  • Java 方法引用详解
  • 以简单组合优化为例讨论计算复杂性
  • 网球循环赛日程表生成算法[循环右移迭代算法]
  • (44)MATLAB读取语音信号进行频谱分析
  • Codeforces Round 979 (Div. 2)
  • Spark 基础概念
  • Systemd: service传递进程参数
  • ip-geoaddress-generator 基于IP的真实地址生成器
  • STM32F407变量地址如何指定到iram1
  • 项目模块四:Channel模块
  • 世界脑力锦标赛资料,最强大脑教程
  • 同济子豪兄--传统图机器学习的特征工程-节点【斯坦福CS224W】
  • 为图片添加水印(Python)
  • 控制系统 状态观测问题 Kalman卡尔曼(附MATLAB实现)