GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C++ Tutorial
  • Interview Questions
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • OOP
  • Exception Handling
  • STL
  • DSA C++
  • Pointers in C++
  • Function in C++
  • Introduction2 min read
  • Data Types4 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Function Pointer in C++ - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • C++ Tutorial
  • Interview Questions
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • OOP
  • Exception Handling
  • STL
  • DSA C++

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 Function

Every 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:

multiply; // Represents the address of the function multiply

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:

  • Calling functions indirectly
  • Passing functions as arguments
  • Implementing callbacks
  • Creating function tables
Function Pointer in C++
Function Pointer in C++

Syntax

return_type (*FuncPtr) (parameter type, ....);

Example:

int (*func)(int, int);

Referencing and Dereferencing a Function Pointer

1. Referencing: Assigning a function’s address to the function pointer.

Syntax:

FuncPtr= function_name;

2. Dereferencing: Invoking the function using the pointer. The dereference operator * is optional during function calls.

Syntax:

FuncPtr(10, 20); // Preferred
(*FuncPtr)(10, 20); // Also valid

Calling a Function Using a Function Pointer

In this example, we see how we point a pointer to a function and call it using that pointer:

C++
#include <iostream>
using namespace std;

int multiply(int a, int b) {
    return a * b;
}

int main() {
    int (*func)(int, int);

    // func points to multiply
    func = multiply;

    int prod = func(15, 2);
    cout << "The value of the product is: " << prod << endl;

    return 0;
}

Output
The value of the product is: 30

Explanation:

  • func stores the address of multiply
  • Calling func(15, 2) executes multiply
  • The call is equivalent to a direct function call

Passing a Function Pointer as a Parameter

Instead of passing a function’s return value, we can pass the function itself. This allows the receiving function to decide when to execute it.

C++
#include <iostream>
using namespace std;

const int a = 15;
const int b = 2;

// Function for multiplication
int multiply() {
    return a * b;
}

// Function accepting a function pointer
void print(int (*funcptr)()) {
    cout << "The value of the product is: " << funcptr() << endl;
}

int main() {
    print(multiply);
    return 0;
}

Output
The value of the product is: 30

Explanation:

  • multiply is passed as a function pointer to print
  • funcptr() invokes multiply inside print
  • This technique is widely used in callbacks and APIs

Related Articles:

  • Pointers in C++
  • Function in C++
Comment

Explore

    C++ Basics
    • Introduction2 min read
    • Data Types4 min read
    • Variables4 min read
    • Operators9 min read
    • Basic Input / Output2 min read
    • Control Flow Statements15+ min read
    • Loops7 min read
    • Functions5 min read
    • Arrays5 min read
    Core Concepts
    • Pointers and References4 min read
    • new and delete Operators5 min read
    • Templates in C++7 min read
    • Struct Union Enum3 min read
    • Exception Handling5 min read
    • File Handling9 min read
    • Multithreading6 min read
    • Namespace5 min read
    OOP
    • OOP Concepts10 min read
    • Inheritance6 min read
    • Polymorphism5 min read
    • Encapsulation3 min read
    • Abstraction4 min read
    Standard Template Library(STL)
    • STL3 min read
    • Container Library3 min read
    • Iterators10 min read
    • Algorithm Library3 min read
    Practice & Problems
    • Interview Questions15+ min read
    • Programming Examples4 min read
    Courses
    • Placement 360 Course2 min read
    • DSA and System Design Course2 min read
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.