Functions :: Functions as Parameters
- This is a little more advanced section on functions, but is very useful. Take this for example:
int applyeqn(int F(int), int max, int min) {What does this function do if we call it with
int itmp;
itmp = F(int) + min;
itmp = itmp - max;
return itmp;
}applyeqn(square(x), y, z);? What happens is that theint F(int)is a reference to the function that is passed in as a parameter. Thus insideapplyeqnwhere there is a call toF, it actually is a call tosquare! This is very useful if we have one set function, but wish to vary the input according to a particular function. So if we had a different function calledcubewe could change how we callapplyeqnby calling the function byapplyeqn(cube(x), y, z);.