Function Pointers & void* in C

From the C cheat sheet · Pointers · verified Jul 2026

Function Pointers & void*

Callbacks and generic pointers.

c
// Quick Reference
int (*op)(int, int) = &add;   // function pointer
int r = op(2, 3);
void *generic;                // points to anything
💡 Function pointers enable callbacks - passing behavior (like qsort's comparator) as data.
⚡ void* is a generic pointer; cast it to the real type before dereferencing.
📌 typedef makes function-pointer types readable: typedef int (*BinOp)(int,int).
🟢 qsort/bsearch take a void* comparator - the classic function-pointer use in C.
function-pointersvoid-pointer

More C tasks

Back to the full C cheat sheet