[prev] 75 [next]

Function Pointers (cont)

Examples of use:

int square (int x) { return x*x; }
int timesTwo (int x) { return x*2; }

int (*fp) (int);
//Point to the square function and use it
fp = □
int n = (*fp)(10);

//It also works without the '&'
fp = timesTwo;
n = (*fp)(2);

//Normal function notation also works
n = fp(2);