当前位置:网站首页>3. Function pointers and pointer functions
3. Function pointers and pointer functions
2022-07-02 14:31:00 【Little BigUs】
Function pointers and pointer functions
A function pointer
A function pointer is a pointer , Point to a function , The return value and parameter list of the pointed function must be the same as The return value of pointer definition is the same as the parameter list .
For example, the following code :
#include<stdio.h>
void pp()
{
printf("this is function pp!\n");
}
void ppp()
{
printf("this is function ppp!\n");
}
int main(void)
{
void (*p)();
p = pp;
p();
p = ppp;
p();
return 0;
}
It defines a point The return value is void, Function pointer with empty argument list , And two functions are defined pp and ppp, And then they will p Point to these two functions and call the function . This is the function pointer .*p The surrounding brackets must not be omitted , Otherwise it will be wrong . Use () after p With the first * combination , therefore p It's a pointer .
Note that when assigning values above, the function name is directly assigned to the pointer , We all know that the pointer points to the address , The previous pointer to the variable needs to add a & This address symbol , When the function pointer points to a function, you don't need , This shows that the function name is actually an address ,
printf("%p\n",pp);
printf("%p\n",&pp);
We can try printing the above two values again , One is printing pp Value , One is printing pp The address of , We can find that these two values are the same , That is to say whether pp still &pp All represent addresses , So the assignment of the previous pointer can not only be p = pp; It can also be p = &pp; Of course, we usually use p = pp; It's not convenient to lose one symbol ?
Pointer function
The pointer function is a function , The return value of this function is a pointer .
for example int* f(int a, int b); Is the definition of a pointer function , The return value of this function must be a int Pointer to type .
() Has a higher priority than *, therefore f With the first () combination ,f It's a function .
Function pointer array
seeing the name of a thing one thinks of its function , This is an array , Every element in the array is a function pointer , A function pointer is a pointer to a function . All elements in an array must be of the same type , So all function pointers in the array must point to functions of the same type .
int (*p[10])(int a, int b);
边栏推荐
- Available solution development oral arithmetic training machine / math treasure / children's oral arithmetic treasure / intelligent math treasure LCD LCD driver ic-vk1622 (lqfp64 package), original te
- Fabric.js 上划线、中划线(删除线)、下划线
- Using computed in uni app solves the abnormal display of data () value in tab switching
- 1、编辑利器vim
- Openharmony notes --------- (4)
- Fabric.js 自由绘制圆形
- 默认插槽,具名插槽,作用域插槽
- 自定义事件,全局事件总线,消息订阅与发布,$nextTick
- [development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
- c# 水晶报表打印
猜你喜欢

默认插槽,具名插槽,作用域插槽

Yyds dry goods inventory software encryption lock function

Design of non main lamp: how to make intelligent lighting more "intelligent"?

C crystal report printing

没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法

Fabric.js 缩放画布
![[Hongke technology sharing] how to test DNS server: DNS performance and response time test](/img/f4/d8c21d6c33985fd6d819cd44c22c72.png)
[Hongke technology sharing] how to test DNS server: DNS performance and response time test

《可供方案开发》口算训练机/数学宝/儿童口算宝/智能数学宝 LCD液晶显示驱动IC-VK1622(LQFP64封装),原厂技术支持

The most complete analysis of Flink frame window function

Fabric. Usage of JS eraser (including recovery function)
随机推荐
Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
Design of non main lamp: how to make intelligent lighting more "intelligent"?
Adhere to the foundation of 20 minutes go every day II
docker mysql
Data Lake (11): Iceberg table data organization and query
<口算練習機 方案開發原理圖>口算練習機/口算寶/兒童數學寶/兒童計算器 LCD液晶顯示驅動IC-VK1621B,提供技術支持
NLA自然语言分析实现数据分析零门槛
联合搜索:搜索中的所有需求
[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
Qt原代码基本知识
跨服务器数据访问的创建链接服务器方法
Multi rotor aircraft control using PID and LQR controllers
PyQt5_QScrollArea内容保存成图片
<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
Fabric. JS dynamically set font size
1、编辑利器vim
4、数组指针和指针数组
Fabric. JS manual bold text iText
The most complete analysis of Flink frame window function
千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?