A callback is a function passed as an argument into another function, so the receiving function can "call back" into your code. It decouples a generic algorithm from the specific behavior it needs. qsort is the canonical example: it sorts any array of any type because the caller supplies a comparison function, qsort calls it whenever it needs to order two elements, without knowing anything about the data. The same pattern underlies event handling ("call this function when the button is pressed"), asynchronous I/O ("call this when the DMA transfer completes"), and dependency inversion generally. Callbacks turn "the library calls fixed code" into "the library calls your code," which is what makes generic, reusable, event-driven APIs possible.
C Programming · Interview question
What is a callback and why is it useful?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Function Pointers & Callbacks
Store a function in a variable, pass behavior as an argument, and build dispatch tables: the mechanism behind qsort, HAL callbacks, and interrupt vector tables.