使用typedef 重写 函数指针

184 阅读1分钟

在一次笔试中遇到了这样一道题目

题目:使用typedef的方法,重写此函数签名,使之更加清晰易懂。

int (*(*f())())() {
    printf("this is a function \n");
    return 0;
}

我的结果为:

int (*(*f())())() {
    printf("this is a function \n");
    return 0;
}

typedef int (*f_0)();
typedef f_0 (*f_1)();
typedef f_1 (*f_2)();

int main() {

    f_2 x;
    x = f;
    (*x)();

    return 0;
}