Pointer to function in c
Like the pointer to normal variables, we can also use pointers to point the functions.
In this tutorial, we will learn how to use function pointer with an example.
Is each function has unique memory address?
Yes. Like every variables function also has unique memory address.
Function pointer syntax
We must enclose the function pointer variable with (). like (*fptr).
Where *fptr is a function pointer, capable of referring a function whose return type is void and also it will not take any argument ().
Similarly, if we want to point a function whose return type is int and it takes one integer argument i.e. int fun(int); then the declaration will be,
Referencing and Dereferencing of Function Pointer
1. Declare correct function pointer.
2. Assign function address to that pointer.
1. Calling the actual function using the function pointer.
Using value at operator *, we can call the function. i.e. (*fptr)();