#include <iostream>
usingnamespace std;
int addition (int a, int b)
{ return (a+b); }
int subtraction (int a, int b)
{ return (a-b); }
int operation (int x, int y, int (*functocall)(int,int))
{
int g;
g = (*functocall)(x,y);
return (g);
}
int main ()
{
int m,n;
int (*minus)(int,int) = subtraction;
m = operation (7, 5, addition);
n = operation (20, m, minus);
cout <<n;
return 0;
}
Can someone give me a simple walk-through/trace of whats going on here? Is minus simply pointing to the function 'subtraction'?
How does the third parameter of 'operation' function work?
Is minus simply pointing to the function 'subtraction'?
Yes.
How does the third parameter of 'operation' function work?
It is a pointer to function taking two integers and returning integer. In your program pointer to subtraction (which takes two integers and returns integer) is passed.
What about line 22? m = operation (7, 5, addition);
Is 'addition' also a pointer to function? It was never declared a pointer like 'minus' was, so im confused about that. If its NOT a pointer to function, how is it passed to the third parameter in 'operation'?