Created
March 22, 2013 22:28
-
-
Save mchirico/5225254 to your computer and use it in GitHub Desktop.
An example of a function pointer 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> | |
#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