How to pass a runnable procedure (a function) as a parameter and run it in C

2 Answers

0 votes
#include <stdio.h>

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

void say() {
    printf("abcd\n");
}

int main() {
    control(say); // Passing function pointer
    
    return 0;
}



/*
run:

abcd

*/

 



answered May 21, 2025 by avibootz
0 votes
#include <stdio.h>

// Function pointer type definition
typedef void (*FuncPtr)();

void control(FuncPtr f) {
    f();
}

void say() {
    printf("abcd\n");
}

int main() {
    control(say); // Passing function pointer
    
    return 0;
}


/*
run:

abcd

*/

 



answered May 21, 2025 by avibootz
...