Skip to content

Instantly share code, notes, and snippets.

@afaquejam
Created July 7, 2014 14:43
Show Gist options
  • Save afaquejam/15a46f86cba2dddc3434 to your computer and use it in GitHub Desktop.
Save afaquejam/15a46f86cba2dddc3434 to your computer and use it in GitHub Desktop.
C Function Pointers Example
#include <stdio.h>
int add(int, int);
int substract(int, int);
int perform(int (*doMath)(int, int), int a, int b) {
return doMath(a, b);
}
void main (int argc, char *argv[]) {
int (*doMath)(int, int);
int var = 1;
if(var)
printf("%d \n", perform(add, 1, 2));
else
printf("%d \n", perform(substract, 1, 2));
}
int add(int a, int b) {
return a + b;
}
int substract(int a, int b) {
return a - b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment