Function Returning Itself

后端 未结 9 725
鱼传尺愫
鱼传尺愫 2020-11-27 04:59

Is it possible to declare some function type func_t which returns that type, func_t?

In other words, is it possible for a function to retur

9条回答
  •  星月不相逢
    2020-11-27 05:28

    #include 
    #include 
    #include 
    
    typedef void *(*fptr)(int *);
    void *start (int *);
    void *stop (int *);
    void *start (int *a) {
             printf("%s\n", __func__);
             return stop(a);
    }
    void *stop (int *a) {
             printf("%s\n", __func__);
             return start(a);
    }
    int main (void) {
             int a = 10;
             fptr f = start;
             f(&a);
             return 0;
    }
    

提交回复
热议问题