What do you mean by “Pointers to Function”? What are Function Pointers ?
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
We can use a function in two ways: one is to invoke a function and the second is to obtain the address of a function. This address that is obtained is called as pointer to the function and is used to invoke the function.
E.g. we have a function named display and we will invoke this function using a pointer to this function as follow:
void display (string s) /* … */
void (*ptr)(string); //pointer to a function
ptr = &display; //assign the address of the function
ptr (“hello”); // call the function
In the above example the compiler will discover that ptr is a pointer to the function display and calls the function. The dereferencing of a pointer to a function using a * is optional. Similarly it is not necessary to use & to get the address to the pointer.
As pointers to functions have argument types declared just like the functions themselves, therefore in pointer assignments the complete function type must exactly match. A function name does not constitute its type. A function type is determined by its return type and its parameter list
Related Articles
- What is Function Overloading in C++ ?
- What are Virtual Functions ? Why do we need Virtual Functions? Explain with an example.
- What is the Difference between Overloaded Functions and Overridden Functions ?
- What is a NULL pointer? How is it different from an unitialized pointer? How is a NULL pointer defined?
- What is ‘this’ Pointer (object) in C++


