A callback function is basically any executable code passed as a parameter to other code that is expected to be called or executed at a specific time. We can define it in other words as follows: If a reference to a function is passed as a parameter to another function to call, it is called a callback function.
In C language, we must use function pointers to call callback functions. The following code shows how the callback function performs its task.
#include<stdio.h> void my_function() { printf("This is a normal function."); } void my_callback_function(void (*ptr)()) { printf("This is callback function.</p><p>"); (*ptr)(); //calling the callback function } main() { void (*ptr)() = &my_function; my_callback_function(ptr); }
This is callback function. This is a normal function.
The above is the detailed content of callback function in C. For more information, please follow other related articles on the PHP Chinese website!