Function pointers
Store a function's address in a variable, pass callbacks to qsort with a comparator, and build a dispatch table that maps command names to C functions.
- The skill
- Pass functions around as values: write comparators for qsort, dispatch commands from a table and write your own function that takes a callback.
- You make
- A sorted leaderboard, a fixed race-time sort, a command table and a pick-the-best function that works on any type.
Premium lesson
£7.99 a month or £59 a year. Cancel any time.
Builds on 28 Hash tables. Free to try: C Foundations and the playground.
Passed
You can now
You have what you need for a project: Word counter with a hash table Premium 2.5 hours, A mini shell Premium 4 hours
Step 1 of 9
exercise_1.c
You've reached the good stuff.
5 exercises in this lesson, checked as you type. Premium opens every lesson after Foundations, in all four courses.
C, 32-bit: int and pointers are 4 bytes