Last active
March 16, 2016 18:24
-
-
Save kenOfYugen/91e10eb09df2ad1daeab to your computer and use it in GitHub Desktop.
Pointer Function examples in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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