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 115 views
1 answer 140 views
1 answer 145 views
2 answers 167 views
1 answer 149 views
1 answer 144 views
4 answers 253 views
...