C Function Pointer
As we know that we can create a pointer of any data type such as int, char, float, we can also create a pointer pointing to a function. The code of a function always resides in memory, which means that the function has some address. We can get the address of memory by using the function pointer.
Let's see a simple example.
The above code prints the address of main() function.
Output
In the above output, we observe that the main() function has some address. Therefore, we conclude that every function has some address.
Declaration of a function pointer
Till now, we have seen that the functions have addresses, so we can create pointers that can contain these addresses, and hence can point them.
Syntax of function pointer
For example:
In the above declaration, *ip is a pointer that points to a function which returns an int value and accepts an integer value as an argument.
Let's understand the function pointer through an example.
Output