/** * A More realistic, but still quite useless, example of function * pointers * @author gtowell * Created: April 2021 * **/ #include /** * Apply the operation passed in as a function pointer to the * other params * @param f -- a pointer to a function. The function must return * an int and it must take two ints as param * @param a -- an int * @param b -- another int * @return the value that result from applying the passed function * to the two params * **/ int op(int(*f)(int,int), int a,int b) { return (*f)(a, b); } /** * Multiply two integers * @param a an integer * @param b another integer * @return the product of the two integers * **/ int mult(int a, int b) { return a * b; } /** * Divide two integers but go UP if remainder > 0. * @param a an integer * @param b another integer * @return the product of the two integers * **/ int div(int a, int b) { return (a / b) + ((a % b == 0) ? 0 : 1); } int main(int argc, char const *argv[]) { printf("%d\n", op((*mult),3,4)); printf("%d\n", op((*div),20,4)); return 0; }