Hey gurus,

I am completely confussed with the functionality of the Function Pointers.

Can anyone help me out in knowing where exactly this function pointers are used.

Here is the simple example which i have copied from one of the books.

/****************************************************************************/
#include <iostream>
using namespace std;
void func()
{
cout << "func() called..." << endl;
}

int main()
{
void (*fp)(); // Define a function pointer

fp = func; // Initialize it

printf("value in *fp after initialize is %d\n",(*fp));
printf("after initialize fp is %d\n",fp);

(*fp)(); // Dereferencing calls the function

void (*fp2)() = func; // Define and initialize
(*fp2)();

return 0;
}
/****************************************************************************/

In this example what exactly is the need of the function pointer "fp". As we can directly call the function
"func()".

/*****************************************************************************/
void (*fp)(); // Define a function pointer
/*****************************************************************************/

Is this the correct way to define. As i know that this is something called declaration
but not definition.

/*****************************************************************************/
printf("value in *fp after initialize is %d\n",(*fp));
printf("after initialize fp is %d\n",fp);
/*****************************************************************************/

what will be the output of the above statement.

Thanks in advance.

venky