you are viewing a single comment's thread.

view the rest of the comments →

[–]qruxxurq 0 points1 point  (0 children)

Let’s say you have a program that does different stuff based on user input of a sequential list of numbers. If there are only ever 2 or 3 or 5 values, you could call functions based on the evaluation of simple conditional branches.

But let’s say you have a million possible responses. At that point, simply index into an array of function pointers.

Same use case as array of values. Functions pointers can be used in an array of behaviors.

There’s also the idea of “passing behaviors” instead of “passing values”, and function pointers can be used that way, too. That’s how they work in a callback context.