Function Pointers and Callbacks in C++ Last Updated : 01 Aug, 2025 Comments Improve Suggest changes 1 Likes Like Report In C++, a callback is a function passed to another function using a function pointer, as function names can't be passed directly. This allows storing and invoking functions dynamically.Function Pointer to a CallbackTo create a function pointer to any particular callback function, we first need to refer to the signature of the function. Consider the function foo()int foo(char c) { .......}Now the function pointer for the following function can be declared as:int (*func_ptr)(char) = &foo;This function pointer allows you to call the function foo() indirectly using func_ptr. We can also pass this function pointer to any other function as an argument allowing the feature of callbacks in C++.C++ Program to Illustrate the Use of Callback C++ // C++ program to illustrate how to use the callback // function #include <iostream> using namespace std; // callback function int foo(char c) { return (int)c; } // another function that is taking callback void printASCIIcode(char c, int(*func_ptr)(char)) { int ascii = func_ptr(c); cout << "ASCII code of " << c << " is: " << ascii; } // driver code int main() { printASCIIcode('a', &foo); return 0; } OutputASCII code of a is: 97 Create Quiz Comment S susobhanakhuli Follow 1 Improve S susobhanakhuli Follow 1 Improve Article Tags : C++ cpp-pointer CPP-Functions CPP Examples Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like