|  | 
 
| 
int (*select(int))(int,int)
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  这个select函数的返回值是int(*)(int,int),那可不可以这样去理解,把select(int)看成一个变量,然后指向一个函数。这里没理解明白,求讲解。
 我的想法是因为int *(int,int)是返回值,函数的格式不是 返回值+函数名+参数吗,然后我想给他写成(int(int,int)) *select (int)
 
 本帖最后由 java2python 于 2020-5-24 15:54 编辑 
按照4楼的帖子,试了试(函数名最好不要用select,疑似关键字):
 复制代码#include <stdio.h>
#include <windows.h>
typedef int (*xfunc)(int,int);
typedef int (*xxfunc(int))(int,int);
int add11(int a,int b){
    return a+b;
}
int mul11(int a,int b){
    return a*b;
}
xfunc selx(int no) {
    xfunc func;
    if(no == 1) func = add11;
    else func = mul11;
    return func;
}
xxfunc *selxx(int no){
    xxfunc *func;
    func = selx;
    return func;
}
int main(){
    xfunc f1 = selx(1);
    printf("f1(3,5)=%d\n",f1(3,5));
    xxfunc *f3 = selxx(1);
    int x=(f3(1))(3,5);
    printf("(f3(1))(3,5)=%d\n",x);
    x=(f3(2))(3,5);
    printf("(f3(2))(3,5)=%d\n",x);
    system("pause");
    return 0;
}
 | 
 |