Sponsered Links
Categories
Sponsered Links

C Function Pointer Example

 

This is a C function example, In this example we Call sum() through pointer, Function pointer declaration and Call multiply() through pointer.

#include <stdio.h>

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


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


int difference(int x, int y){
  return x - y;
}


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

  var1 = sum;             
  result =
var1(a, b);               
  printf("\n
var1 = sum result = %d", result);

  var2 =
multiply;         
  result =
var2(a, b);               
  printf("\n
var2 = multiply result = %d", result);

  var3 = difference;      
  result =
var3(a, b);               
  printf("\n
var3 = difference result = %d \n", result);
  return 0;
}

 

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved