函数指针在 C 中
函数指针指向代码,就像普通的指针一样。
在函数指针中,可以使用函数名称来获取函数的地址。
函数也可以作为参数传递,并可以从函数中返回。
声明
function_return_type(*Pointer_name)(function argument list)
范例
#include<stdio.h>
int subtraction (int a, int b) {
return a-b;
}
int main() {
int (*fp) (int, int)=subtraction;
//Calling function using function pointer
int result = fp(5, 4);
printf(" Using function pointer we get the result: %d",result);
return 0;
}输出
Using function pointer we get the result: 1
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP