How do you pass a function as a parameter in C?

前端 未结 7 2475
梦谈多话
梦谈多话 2020-11-22 04:08

I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?

7条回答
  •  萌比男神i
    2020-11-22 04:28

    Functions can be "passed" as function pointers, as per ISO C11 6.7.6.3p8: "A declaration of a parameter as ‘‘function returning type’’ shall be adjusted to ‘‘pointer to function returning type’’, as in 6.3.2.1. ". For example, this:

    void foo(int bar(int, int));
    

    is equivalent to this:

    void foo(int (*bar)(int, int));
    

提交回复
热议问题