CJCoding With Joseph

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:

6

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

Expected Output:

6
Topics:
Functions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.