Skip to content

Instantly share code, notes, and snippets.

@mchirico
Created March 22, 2013 22:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchirico/5225254 to your computer and use it in GitHub Desktop.
Save mchirico/5225254 to your computer and use it in GitHub Desktop.
An example of a function pointer in C
#include <stdio.h>
#include <stdlib.h>
double Plus (double a, double b) { return a+b; }
double Mult (double a, double b) { return a*b; }
double Minus (double a, double b) { return a-b; }
double Div (double a, double b) { return a/b; }
void SF(double a, double b, double (*ptF)(double, double))
{
double result = ptF(a,b);
printf("%lf\n",result);
}
int main()
{
SF(10,23,&Plus);
SF(10,23,&Mult);
SF(10,23,&Minus);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment