Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

What are the Function Pointer?Explain with an example?
 Using function pointer we can do almost anything with function name.We can pass parameters to a function that is called as pointer.A classic
example is the library function qsort(), which takes a pointer to a function. This pointer often is coded as a constant; you might, however, want to code it as a function pointer variable that gets assigned the correct function to qsort()�s compare.
I have given you a example of Function pointer.

function named function() is defined which will be called through a function pointer. A function named caller() accepts as parameters a function pointer and an integer, which will be passed as arguments to the function that will be called by caller(). 

#include <stdio.h>
static void function(int a)
{
   printf("function: %d
", a);
}
static void caller(void (*func)(int), int p)
{
   (*func)(p);
}
int main(void)
{
   caller(function, 10);
   return 0;
}