CJCoding With Joseph
15free / daySign inCreate account

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 is commands, 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 operands a and b.

For each command print one line in exactly this form:

name(a, b) = result

using the matching entry of the names array.

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
Topics:
Pointers
📥 Auto-Input:
3\n0 6 3\n2 4 5\n3 9 -2\n
This input is automatically fed to your program's stdin
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.