39. Function Pointer Dispatch Table

You are building a simple math command handler. You are given two integers and a command code:

  • 0 → Add
  • 1 → Subtract
  • 2 → Multiply
  • 3 → Divide (integer division, assume non-zero)

 

Your task:

  • Create an array of function pointers, each pointing to one of the above operations.
  • Based on the command code, use the function pointer to invoke the correct operation.
  • Return the result.
     

No if-else or switch-case
Must use a function pointer array
 

Example-1

Input: a = 10, b = 5, command = 0
Output: 15


Example-2

Input: a = 20, b = 8, command = 1
Output: 12


Example-3

Input: a = 6, b = 3, command = 3
Output: 2


 

Loading...

Input

10 5 0

Expected Output

15