Skip to content

Instantly share code, notes, and snippets.

@omerk
Created August 17, 2012 15:51
Show Gist options
  • Save omerk/3380077 to your computer and use it in GitHub Desktop.
Save omerk/3380077 to your computer and use it in GitHub Desktop.
C function pointer demo
#include <stdio.h>
int add(int a, int b)
{
return a + b;
}
int addtimestwo(int (*fp)(int,int), int a, int b)
{
return (*fp)(a, b) * 2;
}
int main(void)
{
int a = 3, b = 5;
int (*fp)(int, int) = &add;
printf("add: %d\n", (*fp)(a, b));
printf("addtimestwo: %d\n", addtimestwo(fp, a, b));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment