Function pointer as an argument

argument-passing, c, function-pointers

Solution

Definitely.

void f(void (*a)()) {
    a();
}

void test() {
    printf("hello world\n");
}

int main() {
     f(&test);
     return 0;
}

Problem

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?

Original source

Related problems