Skip to content

Instantly share code, notes, and snippets.

@Ceasar
Created November 12, 2012 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ceasar/4057268 to your computer and use it in GitHub Desktop.
Save Ceasar/4057268 to your computer and use it in GitHub Desktop.
Example of how to implement a higher order function in C.
/*
* Example of higher order functions in C.
*/
#include <stdio.h>
void func ( void (*f)(int, int) ) {
int ctr = 0;
for (ctr; ctr < 5; ctr++) {
(*f)(ctr, ctr);
}
}
void print (int x, int y) {
printf("%d %d\n", x, x + y);
}
void main() {
func(print);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment