What is a “callback” in C and how are they implemented?
There is no “callback” in C – not more than any other generic programming concept. They’re implemented using function pointers. Here’s an example: void populate_array(int *array, size_t arraySize, int (*getNextValue)(void)) { for (size_t i=0; i<arraySize; i++) array[i] = getNextValue(); } int getNextRandomValue(void) { return rand(); } int main(void) { int myarray[10]; populate_array(myarray, 10, getNextRandomValue); … … Read more