# 如何通过函数指针调用函数(实现代码)

int (*p) (int ,int );

int【指针变量p指向的函数的类型】 （*p）【p是指向函数的指针变量】 ( int,int )【p所指向的形参类型】;

int max  (int, int );

int【函数的类型】 max【函数名】 ( int,int )【函数的形参类型】;

#include<iostream>

using namespace std;

int main(){

int max(int x,int y);

int a,b,c,m;

cin>>a>>b>>c;

m=max(max(a,b),c);

cout<<"Max="<<m<<endl;

return 0;

}

int max(int x,int y){

int z;

if(x>y){

z=x;

} else{

z=y;

}

return z;

}

#include<iostream>

using namespace std;

int main(){

int max(int x,int y);

int (*p) (int x,int y);

p=max;

int a,b,c,m;

cin>>a>>b>>c;

m=(*p)((*p)(a,b),c);

cout<<"Max="<<m<<endl;

return 0;

}

int max(int x,int y){

int z;

if(x>y){

z=x;

} else{

z=y;

}

return z;

}

#include<iostream>

using namespace std;

int main(){

int max(int x,int y);

int (*p) (int x,int y);

p=max;

int a,b,c,m;

cin>>a>>b>>c;

m=p(p(a,b),c);

cout<<"Max="<<m<<endl;

return 0;

}

int max(int x,int y){

int z;

if(x>y){

z=x;

} else{

z=y;

}

return z;

}

#include<iostream>

#include<math.h>

using namespace std;

double fun1(double n){

double r;

r=n+1;

return r;

}

double fun2(double n){

double r;

r=2*n+3;

return r;

}

double fun3(double n){

double r;

r=(pow(n,2)+1);

return r;

}

double Squar(int a, double x, double(*p)(double )){

double r,z;

z=(*p)(x);

r=pow(z,a);

return r;

}

int main(){

double fun1(double n);

double fun2(double n);

double fun3(double n);

double Squar(int a, double x, double(*p)(double ));

double x;

cin>>x;

cout<<"(x+1)^1=";

cout<<Squar(1,x,fun1)<<endl;

cout<<"(2x+3)^2=";

cout<<Squar(2,x,fun2)<<endl;

cout<<"(x^2+1)^3=";

cout<<Squar(3,x,fun3)<<endl;

cout<<endl;

return 0;

}