Using a function pointer - C++ Function

C++ examples for Function:Function Pointer

Description

Using a function pointer

Demo Code

#include <iostream>
using namespace std;
void func() {//from   w  w  w . j av  a 2 s  .  com
   cout << "func() called..." << endl;
}
int main() {
   void (*fp)();  // Define a function pointer
   fp = func;  // Initialize it
   (*fp)();    // Dereferencing calls the function
   void (*fp2)() = func;  // Define and initialize
   (*fp2)();
}

Result


Related Tutorials