CJCoding With Joseph
15free / daySign inCreate account

Function Pointer to Apply Operation

Write a function int applyOp(int a, int b, int (*op)(int, int)) that calls the function pointed to by op with a and b and returns the result. A function int subtract(int a, int b) returning a - b is provided. In main, call applyOp(10, 4, subtract) and print the result (see Expected Output).

The third parameter is a pointer to a function that takes two ints and returns an int.

Expected Output:

6

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Functions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.