How define an array of function pointers in C

前端 未结 5 1545
野趣味
野趣味 2020-11-28 02:05

I\'ve a little question. I\'m trying to define an array of function pointers dynamically with calloc. But I don\'t know how to write the syntax. Thanks a lot.<

5条回答
  •  一整个雨季
    2020-11-28 02:28

    I put a small example here that may help you

    typedef void (*fp)(int); //Declares a type of a void function that accepts an int
    
    void test(int i)
    {
        printf("%d", i);
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        fp function_array[10];  //declares the array
    
        function_array[0] = test;  //assings a function that implements that signature in the first position
    
        function_array[0](10); //call the cuntion passing 10
    
    }
    

提交回复
热议问题