← Back to Pointers
Question 464
Arithmetic Dispatch Table of Function Pointers
Arithmetic Dispatch Table of Function Pointers
The four operations and their names are already written for you. Build a dispatch table int (*ops[4])(int, int) = { add, sub, mul, max_of }; and use it to run the commands from input. Input: the first line iscommands, the number of commands that follow. Each command is three integers on its own line: an operation code (0 = add, 1 = sub, 2 = mul, 3 = max) and the two operandsaandb. For each command print one line in exactly this form:name(a, b)= result using the matching entry of thenamesarray. For the input: 3 0 6 3 2 4 5 3 9 -2 the output is exactly what is shown in Expected Output. Each line ends with a newline. Do not use if/else or switch to pick the operation — index the table.
Expected Output:
add(6, 3) = 9 mul(4, 5) = 20 max(9, -2) = 9
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.