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

#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; }


Happy Exploring!



No comments:

Post a Comment

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