Let's consider a function:
int fun(int x, int y) {
return x + y;
}
A function is just a piece of code located somewhere in the memory. So, it has its own address, provided by a pointer.
The function type is a special data type that can contain a function pointer, like fun
:
int (*f)(int, int) = fun;
Where:
f
is the name of the variable.(int, int)
are types of parameters of the function. Note that is not required a name for those.fun
is the function that we assign to this function type.
Rename a function pointer:
typedef int (*custom_name)(int, int);