Function Pointers

The syntax for declaring a function pointer:

void (*foo)(int);

foo is a pointer to a function taking one argument, an integer, and that returns void
Complex Case:

void *(*foo)(int *);

Here, the key is to read inside-out; notice that the innermost element of the expression is *foo, and that otherwise it looks like a normal function declaration. *foo should refer to a function that returns a void * and takes an int *. Consequently, foo is a pointer to just such a function

Initializing and Using Function Pointers

Function Pointers can be ideally used to implement Callback:

void pointer:

  • The void keyword is used to specify that a function either doesn’t take arguments or doesn’t return a value. The void keyword can also be used to create a generic pointer–a pointer that can point to any type of data object.
  • For example, the statement

void *x;

declares x as a generic pointer. x points to something; you just haven’t yet specified what