Skip to content

Instantly share code, notes, and snippets.

@kokosabu
Created October 29, 2015 14:13
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 kokosabu/65664512fc7c5f930760 to your computer and use it in GitHub Desktop.
Save kokosabu/65664512fc7c5f930760 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
struct func {
int (*add)(int i, int j);
int (*sub)(int i, int j);
};
int add(int i, int j)
{
return i + j;
}
int sub(int i, int j)
{
return i - j;
}
int main()
{
struct func *f;
f = malloc(sizeof(struct func));
f->add = add;
f->sub = sub;
printf("%d\n", f->add(10, 20));
printf("%d\n", f->sub(30, 20));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment