A function pointer is a special type of pointer who’s value is the address of the first instruction of a function, as opposed to the address of a value.
Syntax
void ping(){
//...
}
void foo() {
void (*aFunc) ();
aFunc = ping; //Assigns function ping to variable
aFunc(); //Calls ping
}Note above that function pointer declarations need to be fully typed, with a return type, a name, and declaring the parameters and their names as well.
The name of the function is treated as its address, in other words with consideration to the code above:
&ping == pingUse
One of the main use cases for function pointers is to be able to do dynamic dispatch, i.e. determining which function to call at runtime rather than compile time. This enables polymorphism for example. In general, they are very useful for abstractions in C.