Search code examples
cfunction-pointersargument-passing

Function pointer as an argument


Is it possible to pass a function pointer as an argument to a function in C?

If so, how would I declare and define a function which takes a function pointer as an argument?


Solution

  • Definitely.

    void f(void (*a)()) {
        a();
    }
    
    void test() {
        printf("hello world\n");
    }
    
    int main() {
         f(&test);
         return 0;
    }