How to pass function pointer to a function in C

1 Answer

0 votes
#include <stdio.h>

void f1(void) {
    puts("f1");
}

void f2(void) {
    puts("f2");
}

void control(void (*p)(void)) {
    p();
  }

int main(void)
{
    void (*p)(void);

    p = f1;
    control(p);
    
    p = f2;
    control(p);

    return 0;
}




/*
run:

f1
f2

*/

 



answered May 9, 2023 by avibootz

Related questions

1 answer 197 views
1 answer 230 views
1 answer 241 views
2 answers 306 views
1 answer 233 views
1 answer 242 views
4 answers 420 views
...