In this lecture, you'll learn about callback functions. The big idea is we pass in a pointer to a function as an argument to a different function. Later on, that different function can call back the function that we passed it. The pointer to function that we pass in is called the callback function, and the function that does the calling back is called a higher-order function. Let's go see how this works. In this example, we have three functions. We have a LessThan function that will return true if first number is less than second number, and will return false otherwise. We have a GreaterThan function that will return true if first number is greater than second number, and false otherwise. Then the interesting function is the FindExtreme function, which returns an int, so we pass in a reference to a vector of int called values, and here's the new stuff. We also pass in a pointer to a function that we're going to call compare, that's the parameter name, and this function returns a bool, and has two int parameters. You shouldn't be surprised to recognize that function signature as the function signature for the LessThan function and the GreaterThan function. Down here in my main function, I create a vector of values and I set a MinValue variable to the results of calling the FindExtreme function with that vector of ints and the address of my LessThan function. Then I set a MaxValue variable to the result of calling FindExtreme with the vector and the address of the GreaterThan function. This part here is me passing in a callback function into the higher-order function called FindExtreme. Let's look at the implementations of our function bodies. LessThan is straightforward, it just returns whether our first number is less than second number, GreaterThan is very similar, and of course, this is the interesting function for this example. Remember the values and a pointer to a function that returns a bool with two int parameters and that parameter is called compare. We're going to just assume at least one value is provided, so I'll set an ExtremeValue variable equal to the first element of my values vector, and then I'll iterate over the rest of the vector, and here is the interesting part. I'll call the function that's pointed to by the compare perimeter, and I'll pass in the current value I'm looking at in the vector and the extreme value, it might be the smallest, it might be the largest, we don't know, but the extreme value that we've found so far, and if the function that's pointed to by the compare pointer to function parameter returns true, then we just found a new extreme based on whatever that comparison does. If we just found a new extreme, we said ExtremeValue equal to the current element of the vector that we're looking at because we just found a new extreme value. Then when we're all done, we return that extreme value. This code here doesn't have to have any idea how compare works. This function just uses a pointer to whatever function was passed in as an argument when the FindExtreme function was called to do whatever comparison is required, and keep track of the current extreme value. When I run my code, you'll see that the first time I called FindExtreme with a pointer to the less than function, I found the minimum value. Then the second time when I called FindExtreme with a pointer to the greater than function as an argument, I got the maximum value. Just to show you that that's actually true back at the vector, you can see that 1 is my minimum value and max is max maximum value. To recap, in this lecture, you learned how we can pass a callback function into a higher-order function, you learned how we can call back that function from the higher-order function, and you should know that using callback functions lets us implement a standard object-oriented pattern called the observer pattern. In other words, the callback function says, "I would like to observe when something happens," and the higher-order function, when it calls back that function says, "Hey, it happened. I'm glad you wanted to observe it, now you can." That's really the core idea behind event handling.