Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

pointer to functions in C++

+8 votes
asked Jun 20, 2025 by Serge (200 points)

1 Answer

+1 vote
answered Jun 22, 2025 by Proxmega Game (200 points)
Suppose you have a function like:

int add(int a, int b)

{ return a + b; }

A pointer to a function with the same signature (int(int, int)) is declared like this:

int (*funcPtr)(int, int);

You can then assign the function to the pointer:

funcPtr = add;

And call the function via the pointer:

int result = funcPtr(2, 3); // Calls add(2, 3)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...