I have on function that has takes another function as the argument:
#include <iostream>
using namespace 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);
}
When i use it in the main
function:
int main ()
{
int m,n;
int (*minus)(int,int) = subtraction;
m = operation (7, 5, addition);
n = operation (20, m, *minus);
cout <<n;
return 0;
}
Other ways to use addition
and minus
in operation
:
m = operation (7, 5, &addition);
n = operation (20, m, *minus);
or:
m = operation (7, 5, *addition);
n = operation (20, m, minus);
All of them have the same result: 8
in this case. Are there any differences between them ? What should i use ?