/* function_pointers.c Demonstrates the function pointer type in C. */ #include #include void print_int (int i) { printf("%d\n", i); } //float print_int; // this can't be declared in the same scope as the function named print_int void print_fancy( int i ) { printf( "The int is %d\n", i ); } void process_int( void (*do_it)(int), int the_int_to_process ) { do_it(the_int_to_process); printf( "I have done it\n" ); } int main() { // float print_int; // this will shadow the function. // declare a function pointer // variable's name is func. // the type is a function that returns void and takes an // int as input void (*func)(int); // initialize a function pointer func = print_int; // call a function pointer func(10); process_int( print_int, 20 ); process_int( print_fancy, 20 ); return 0; }