Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int addInt(int n, int m){
- return n + m;
- }
- int timeInt(int n, int m){
- return n * m;
- }
- int calTwoNumbers(int(*functionPtr)(int,int),int n, int m){
- return functionPtr(n,m);
- }
- int main(){
- /************** function pointer - function as parameters *****************/
- int sum = 0;
- // declare function pointer
- int (*functionPtr)(int,int);
- // pass function as parameters:
- sum = calTwoNumbers(addInt,2,3);
- printf("%d\n",sum); // 2 + 3 = 5
- sum = calTwoNumbers(timeInt,2,3);
- printf("%d\n",sum); // 2 * 3 = 6
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment