Pointers to Functions
There are cases where there is a function call in a command but there is no prior knowledge which function is to be called
Example:void *v1, *v2;if (compare(v1,v2) == 0) { …v1, v2 may point to integers or strings or other types. An appropriate compare function should be called, according to the type of the objects pointed to by v1, v2.
Solution:enum {INT, STR}int (*compare)(void*, void*); /*pointer to function*/...switch(type){ case INT: compare = &num_compare; break; case STR: compare = &strcmp; break;} if ((*compare)(v1,v2) == 0) { /*or “compare(v1,v2)” */