Created
April 12, 2013 07:29
-
-
Save jacobabrahamb4/5370199 to your computer and use it in GitHub Desktop.
function_pointers
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> | |
typedef int* intPtr; | |
typedef float (*fPtr) (float, float); | |
float plus(float a, float b){return a+b;} | |
float minus(float a, float b){return a-b;} | |
float multiply(float a, float b){return a*b;} | |
float divide(float a, float b){return a/b;} | |
int main() | |
{ | |
float a=6.0, b=2.0; | |
float (*ptr2fun)(float, float)=NULL; | |
fPtr fp = NULL; | |
ptr2fun = + | |
printf("a+b is : %f \n", ptr2fun(a,b)); | |
ptr2fun = − | |
printf("a-b is : %f \n", ptr2fun(a,b)); | |
fp = &multiply; | |
printf("axb is : %f \n", fp(a,b)); | |
fp = ÷ | |
printf("a/b is : %f \n", fp(a,b)); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment