Skip to content

Instantly share code, notes, and snippets.

@kenOfYugen
Last active March 16, 2016 18:24
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 kenOfYugen/91e10eb09df2ad1daeab to your computer and use it in GitHub Desktop.
Save kenOfYugen/91e10eb09df2ad1daeab to your computer and use it in GitHub Desktop.
Pointer Function examples in C
#include <stdio.h>
int add(int x, int y) {
return x + y;
}
int substract(int x, int y) {
return x - y;
}
int domath(int (*mathop)(int, int), int x, int y) {
return (*mathop)(x, y);
}
int main(void) {
int a = domath(add, 10, 2);
printf("Add gives: %d\n", a);
int b = domath(substract, 10, 2);
printf("Substract gives: %d\n", b);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment