Arrays of Function Pointers
Learn how to create arrays of pointers to a function.
Introduction
Similar to how we can have arrays of ints
, chars
, and int*
(integer pointers), we can have arrays of function pointers.
Each element inside the array will be a pointer to a function. Since each element must have the same type, the functions must have matching signatures.
Motivating example
Let’s revisit the example of printing an array using multiple styles. We already saw this code.
We can see that lines 40–43 are pretty much identical, except for the style function. What if we had 100 style functions? We don’t want to write 100 lines manually.
Access this course and 1400+ top-rated courses and projects.