What is a callback function?
Assume we have a function sort(int *arraytobesorted,void (*algorithmchosen)(void))
where it can accept a function pointer as its argument which can be used at some point in sort()
's implementation . Then , here the code that is being addressed by the function pointer algorithmchosen
is called as callback function .
And see the advantage is that we can choose any algorithm like:
1. algorithmchosen = bubblesort
2. algorithmchosen = heapsort
3. algorithmchosen = mergesort ...
Which were, say,have been implemented with the prototype:
1. `void bubblesort(void)`
2. `void heapsort(void)`
3. `void mergesort(void)` ...
This is a concept used in achieving Polymorphism in Object Oriented Programming