Passing Function to a Function as Parameter - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Passing Function to a Function as Parameter

Share This

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
int funman(int (*) (int x, int y), int x, int y);
int add(int x, int y);
int mul(int x, int y);
int main(void)
{
int i, j, res;
printf("Enter two integer numbers: ");
scanf("%d %d", &i, &j);
res = funman(add, i, j);
printf("\nres is : %d", res);
res = funman(mul, i, j);
printf("\nres is : %d", res);
printf("\n");
return 0;
}
int funman(int (*ptofun) (int x, int y), int x, int y)
{
return (*ptofun)(x, y);
}
int add(int x, int y)
{
return x + y;
}
int mul(int x, int y)
{
return x * y;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Happy Exploring!



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.