C++函数指针

来源:互联网 发布:网络机顶盒 会员 编辑:程序博客网 时间:2024/06/03 17:02
#include <iostream>
using namespace std;
int test(int,int);
int _tmain(int argc, _TCHAR* argv[])
{
#ifdef __STDC__
     cout<<"这是 C 程序。"<<endl;
#endif
#ifdef __cplusplus
     cout<<"这是C++程序。"<<endl;
#endif
 typedef int (*pf)(int,int);
 pf p;
 p = test;
 cout<<p(10,20)<<" | "<<(*p)(11,12)<<" | "<<(*p)(1,2)<<endl;
 system("pause");
 return 0;
}
int test(int m,int n)
{
 cout<<m<<"进入测试 指针函数"<<n<<endl;;
 return m*n;
}

执行结果:

这是C++程序。
1进入测试 指针函数2
11进入测试 指针函数12
10进入测试 指针函数20
200 | 132  | 2

可以看出是从右向左执行。
原创粉丝点击