GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Function Pointer in C++ - GeeksforGeeks Function Pointer in C++Last Updated : 19 Jan, 2026 In C++, pointers store memory addresses. While pointers are commonly used with variables, they can also store the address of a function. A function pointer allows a program to call a function indirectly or pass a function as an argument, enabling flexible and dynamic behavior. Address of a FunctionEvery function resides in memory and therefore has an address. The name of a function can be used to find the address of the function. We can get the address of a function by just writing the function's name without parentheses in the function. Example:
Function Pointer in C++A function pointer is a pointer variable that stores the address of a function with a specific return type and parameter list. Key Uses:
![]() Syntax
Example:
Referencing and Dereferencing a Function Pointer1. Referencing: Assigning a function’s address to the function pointer. Syntax:
2. Dereferencing: Invoking the function using the pointer. The dereference operator * is optional during function calls. Syntax:
Calling a Function Using a Function PointerIn this example, we see how we point a pointer to a function and call it using that pointer:
Output The value of the product is: 30 Explanation:
Passing a Function Pointer as a ParameterInstead of passing a function’s return value, we can pass the function itself. This allows the receiving function to decide when to execute it.
Output The value of the product is: 30 Explanation:
Related Articles:Comment ExploreStandard Template Library(STL) Practice & Problems |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |