How to use pointer to function in C program?


 

#include<stdio.h>
int add(int x, int y){
	return (x+y);
}
int sub(int x, int y){
	return (x-y);
}
void main(){
  int (*func)(int, int);
  int x = 5, y = 6, z;
  func = &add;
  z = (*func)(x, y);
  printf("x = %d, y = %d, z = %d\n", x, y, z);
  func = &sub;
  z = (*func)(x, y);
  printf("x = %d, y = %d, z = %d\n", x, y, z);
}
Download

Comments

Popular posts from this blog