当前位置: 代码迷 >> 综合 >> Typedef中一个“PF Register( PF test )”使用实例
  详细解决方案

Typedef中一个“PF Register( PF test )”使用实例

热度:7   发布时间:2023-12-21 04:41:32.0
#include <stdio.h>//typedef定义一种类型,带有两个int型参数并返回int型数据
typedef int (*PF) ( const int * ,const int *);//选出最大的数
int max( const int *x, const int *y )
{if( *x > *y )return *x;elsereturn *y;
}//用result和number相加
int add( const int *result, const int *number )
{int a; a = *result + *number;return a;
}//Register为PF类型,Register只有一个参数test并且为PF类型
//返回的add为PF类型
PF Register( PF test )
{return add;
}int main()
{   int kk = 2;int kl = 2;PF m;m = Register( max );//把add的入口地址给到m(PF类型)printf( "%d\n", m( &kk, &kl));//结果4return 0;
}

 

  相关解决方案