具有函数指针参数的函数指针

时间:2018-12-08 01:33:00

标签: c parameter-passing function-pointers

谁能帮我解释下面的代码为何起作用。

为什么func = foo行有效。

typedef int (* fx) (int *fy());
unsigned int foo(void);

int main()
{
    fx func;
    func = foo;
    func(&foo);
    return 0;
}

unsigned int foo(void)
{
    printf("Done!");
}

1 个答案:

答案 0 :(得分:1)

这有意义吗?

#include <stdio.h>
typedef int (*fx)(void); // fx is defined as a type of function that returns an int and takes no arguments

int foo(void) {
    printf("Done!");
    // "control reaches end of non-void function"
}

int main() {
    fx func;
    func = foo;
    //func(&foo);
    func();
    return 0;
}
相关问题