About Pointers To Functions in function declarations

后端 未结 4 1720
后悔当初
后悔当初 2020-12-01 18:02
#include
#include

int fun1()
{
    printf(\"I am fun1.\");
    return 0;
}

int fun2(int fun())
{
    fun();
    return 0;
}

int mai         


        
4条回答
  •  情书的邮戳
    2020-12-01 18:51

    Looking to it in a lower level (and in a x86-based architecture):

    int fun2(int fun())
    

    int fun()'s address is pushed into the stack and passed to fun2() function.

    int fun2(int (*fun)())
    

    int fun()'s pointer address is pushed into the stack and passed to fun2() function.

    The result is the same, except that with second one, you pass the fun()'s address by reference, and in the first one you pass it by value.

提交回复
热议问题