当前位置:网站首页>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);
边栏推荐
- Golang 快速生成数据库表的 model 和 queryset
- Selenium element positioning method
- Generally speaking, if the error of inconsistent tab and space occurs frequently
- P1908 逆序对
- Adhere to the foundation of 20 minutes go every day II
- Fabric.js 手动加粗文本iText
- <口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
- 线性dp求解 最长子序列 —— 小题三则
- There is no solution to the decryption error of the remote user 'sa' and the service master password mapped from the remote server 'to the local user' (null) /sa '
- Openharmony notes --------- (4)
猜你喜欢

Selenium element positioning method

你知道Oracle的数据文件大小有上限么?
![[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

Analysis of CPU surge in production environment service

提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”

Whole house Wi Fi: a pain point that no one can solve?

< schéma de développement de la machine d'exercice oral > machine d'exercice oral / trésor d'exercice oral / trésor de mathématiques pour enfants / lecteur LCD de calculatrice pour enfants IC - vk1621

MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)

Pychart connects to the remote server

Teamtalk source code analysis win client
随机推荐
千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?
Go operation redis
PHP linked list creation and traversal
Do you know that there is an upper limit on the size of Oracle data files?
freemarker的使用
YOLOv3&YOLOv5输出结果说明
Fabric. Keep the original level when JS element is selected
NLA自然语言分析实现数据分析零门槛
Openharmony notes --------- (4)
Daily learning 3
Methods of software testing
NLA natural language analysis makes data analysis more intelligent
Quarkus学习四 - 项目开发到部署
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'
给Android程序员的一些面试建议「建议收藏」
OpenHarmony笔记-----------(四)
Fabric.js 缩放画布
Who is better, Qianyuan projection Xiaoming Q1 pro or Jimi new play? Which configuration is higher than haqu K1?
Pychart connects to the remote server