#include <stdio.h>
int add(int, int);
int sub(int, int);
int mul(int, int);
int div(int, int);
int myfunPtr(int , int , int(*)(int, int));
int add(int var1, int var2)
{
return var1 + var2;
}
int sub(int var1, int var2)
{
return var1 - var2;
}
int mul(int var1, int var2)
{
return var1 * var2;
}
int div(int var1, int var2)
{
return var1 / var2;
}
int myfunPtr(int a, int b, int(*argFun)(int, int))
{
int x = 0;
x = (*argFun)(a, b);
return x;
}
int main(int argc, char **argv)
{
int x = 0;
x = myfunPtr(100, 5, add);
printf("o/p : %d\n", x);
x = myfunPtr(100, 5, sub);
printf("o/p : %d\n", x);
x = myfunPtr(100, 5, mul);
printf("o/p : %d\n", x);
x = myfunPtr(100, 5, div);
printf("o/p : %d\n", x);
return 0;
}
A Blog to learn Software Technologies like C, Golang and Java
Passing function as argument in C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment