Skip to content

Instantly share code, notes, and snippets.

@rrmhearts
Last active October 29, 2019 14:48
Show Gist options
  • Save rrmhearts/ee336fdc1cb54f8473aad4bc6bef7641 to your computer and use it in GitHub Desktop.
Save rrmhearts/ee336fdc1cb54f8473aad4bc6bef7641 to your computer and use it in GitHub Desktop.
Passing a Function in C
#include <stdio.h>
void printNumber(int nbr)
{
printf("%d\n", nbr);
}
void myFunction(void (*f)(int))
{
for(int i = 0; i < 5; i++)
{
(*f)(i);
}
}
int main(void)
{
myFunction(printNumber);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment