函数指针
来源:互联网 发布:mac电脑中病毒 编辑:程序博客网 时间:2024/06/09 23:30
函数指针的声明:
函数类型(标识符指针变量)(形参列表);
注意:括号不能去掉,否则就变成指针函数了。
使用规则:
int func(int x);//声明一个函数
int (*f) (int x); //声明一个函数指针
f=func; //将func函数地 首地址赋给指针f
举例说明:
#include <iostream>
using namespace std;
int max(int x,int y)
{
return (x>y?x:y);
}
int main()
{
int max(int x,int y);
int (*f)(int x,int y);
f=max; //表示方式1
int a,b,c,d;
cout<<"please input three integer:"<<endl;
cin>>a>>b>>c;
d=(*f)((*f)(a,b),c); //函数指针的使用
cout<<d<<endl;
return 0;
}
#include <iostream>
using namespace std;
int max(int x,int y)
{
return (x>y?x:y);
}
int main()
{
int max(int x,int y);
int (*f)(int x,int y)=&max; //表示方式2
// f=max;
int a,b,c,d;
cout<<"please input three integer:"<<endl;
cin>>a>>b>>c;
d=(*f)((*f)(a,b),c);
cout<<d<<endl;
return 0;
}
指针函数与函数指针的区别:指针函数,本质上是一种函数,只不过函数地返回类型是某一类型的指针。
指针函数的声明:
函数类型 标识符指针* 函数名(形参列表);
- 指针函数 函数指针
- 函数指针/指针函数
- 指针函数&函数指针
- 函数指针 指针函数
- 函数指针 指针函数
- 指针函数,函数指针
- 函数指针,指针函数,
- 指针函数,函数指针
- 函数指针 指针函数
- 函数指针、指针函数
- 指针函数&函数指针
- 函数指针 指针函数
- 函数指针 指针函数
- 函数指针&指针函数
- 指针函数 函数指针
- 指针函数 &函数指针
- 函数指针&指针函数
- void指针 函数指针
- UVA - 11059 Maximum Product (简单枚举)
- hibernate---CRUD
- Linux命令:free
- 蛇形填数
- HDU2852_KiKi's K-Number(线段树/单点更新)
- 函数指针
- Linux命令:vmstat
- Xlib: connection to ":0.0" refused by server
- 取消基本数据的修改——备忘录模式的应用
- Linux命令:iostat
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
- UVA11389-The Bus Driver Problem
- [DOS批处理]for 命令 /f 参数 通俗讲解(转发)
- 背包问题