First declare a pointer to a function:
typedef int (*Pfunct)(int x, int y);
Almost the same as the function prototype.
But now all you have created is a function pointer type (with typedef ).
So now you are creating a pointer to a function of this type:
Pfunct myFunction; Pfunct myFunction2;
Now assign the addresses of the functions to these, and you can use them the way they are:
int add(int a, int b){ return a + b; } int subtract(int a, int b){ return a - b; } . . . myFunction = add; myFunction2 = subtract; . . . int a = 4; int b = 6; printf("%d\n", myFunction(a, myFunction2(b, a)));
Function pointers are great fun.
source share