Function Pointers

A function pointer holds the address of a callable function. Declaration syntax is notoriously ugly: int (*fp)(int, int) declares a pointer to a function taking two ints and returning int. typedef makes this bearable: typedef int (*binop_t)(int, int). Used for: callbacks (qsort, signal handlers), dispatch tables (vtable-style OOP in C), plugin architectures. The function name itself decays to a pointer in most contexts, so fp = add and fp = &add are equivalent.

Appears In

m02-pointers-memory-model