Pointing to functions : Function Pointer « Function « C / ANSI-C






Pointing to functions

Pointing to functions
#include <stdio.h>

int sum(int x, int y)
{
   return x + y;
}

int product(int x, int y)
{
   return x * y;
}


int main()
{
   int a = 13;
   int b = 5;
   int result = 0;
   int (*pfun)(int, int);

   pfun = sum;
   result = pfun(a, b);
   printf("\npfun = sum   result = %d", result);

   pfun = product;
   result = pfun(a, b);
   printf("\npfun = product         result = %d", result);

}



           
       








Related examples in the same category

1.Implementing arithmetic and array functionsImplementing arithmetic and array functions
2.Arrays of Pointers to functionsArrays of Pointers to functions
3.Passing a Pointer to a function
4.Function pointerFunction pointer
5.Function pointer 2
6.Function pointer: function call
7.Function pointer and use it call a function
8.Array of function pointerArray of function pointer
9.Initialize the function pointer array