[prev] 47 [next]

Programming: Function Pointers (cont)

Function pointers ...
  • are references to memory address of a function
  • are pointer values and can be assigned/passed
Example of use:

// define a function on Lists
int length(List L) { ...as defined above... }
// define a function pointer variable "fp"
int (*fp)(List); 
// assign a value to this variable
fp = &length;   // or, simply, fp = length;
// apply the function being pointed to
n = (*fp)(L);   // same as n = length(L)