Skip to content

Instantly share code, notes, and snippets.

@hduffddybz
Created November 11, 2014 08:05
Show Gist options
  • Save hduffddybz/78b244ee66f34de12b12 to your computer and use it in GitHub Desktop.
Save hduffddybz/78b244ee66f34de12b12 to your computer and use it in GitHub Desktop.
The implementation of callback function in C.
#include <stdio.h>
#include <stdlib.h>
void PrintTwoNumbers(int (*numberSource)(void))
{
printf("%d %d\n", numberSource(), numberSource());
}
int overNineThousand(void)
{
return (rand() % 1000) + 9001;
}
int meaningOfLife(void)
{
return 80;
}
int main(void)
{
PrintTwoNumbers(&rand);
PrintTwoNumbers(&overNineThousand);
PrintTwoNumbers(&meaningOfLife);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment