/*
 * Simple example of function that takes a function pointer as a parameter.
 */
#include <stdio.h>

/* call function and print inputs and outputs */
/* output format:  "for inputs <in1> and <in2>, <msg> is <f(in1, in2)> */
void test_and_print(char * msg, int in1, int in2, int (*f)(int, int));

/* some functions to pass to test_and_print */
int add(int x, int y) { return x+y; }
int multiply(int x, int y) { return x*y; }

/* main */
int main(void) {
    test_and_print("sum", 2, 3, add);
    test_and_print("product", 2, 3, multiply);
    test_and_print("sum", 4, -2, add);
    test_and_print("product", 4, -2, multiply);
    return 0;
}

void test_and_print(char * msg, int in1, int in2, int (*f)(int, int)) {
    printf("for inputs %d and %d, %s is %d\n", in1, in2, msg, f(in1, in2));
}