#include <iostream>
using namespace std;
//函数 指针的使用
int add(int a,int b) {
cout << " add fuction called " << endl;
return a + b;
}
int main()
{
//1.定义函数类型 -- 返回值(类型名字)(参数列表)--这种格式
typedef int (FUNCTION)(int, int);
//使用规则如下,先初始化
FUNCTION * function = NULL;
function = add;
function(1,4);
//2.定义函数指针类型 -- 返回值(类型指针名字)(参数列表)--这种格式
typedef int(*FUNCTION_P)(int, int);
FUNCTION_P fp = NULL;
fp = add;
fp(2,5);
//3.直接定义相匹配的指针
int(*p)(int, int);
p = add;
p(4,7);
}
函数指针的三种 定义和使用方式
最新推荐文章于 2023-09-13 07:55:52 发布