Our next topic is function invocation and the notion of call by value for the parameters, and this is an extremely important topic. So this is central, so you really have to work at understanding this, and as you see, there's a reference that we're following in a text, 5.7. So we're going to look at how parameters behave or arguments behave. They behave call-by-value. A simple function, int compute sum to n, one argument, one parameter, int n semicolon. The body of the function is an internal local variable, sum equals zero, and then we have this for loop. Notice, we don't have a beginning part. That means nothing is done at the beginning. Our testing part is when n stays greater than zero and we decrement n. So we're expecting to pass positive value, and we're going to sum all of the integers up to n and then return that sum. Notice, internally, it seems like n is being reduced to zero. So if n started at 20, this is going to count down to zero. What we're going to see as in the external or calling environment, the actual parameter, the actual variable passed in here, if it is a variable, is unchanged. So imagine that we call this function with an integer m equals five and we want to compute the sum to n of five. Indeed, what should be the answer? It should be 1 plus 2 plus 3 plus 4 plus 5. You should try this out. When we invoke that function, when that function is called, here are the semantics. Here is the meaning of that function, here is how that function is executed. Each expression in the argument list parameters is evaluated. So in this case, it's simple. M was five, but it could have been something else. It could have been five plus m plus 2.5 or 3 times m, or it could have just been an actual value passed. All of those would be appropriate. What happens is, whatever that value is, it has to be converted if necessary to the type of the parameter. In that case, the parameter was an integer parameter. Now, for m, already five in each parameter, there would be no conversion, but it turns out we could've used that expression that would have been double. We could have used 3.5 times m, in which case, the answer would have been 17.5, and in that conversion, it gets lopped off to 17. Again, you might want to try this in your own code if you don't believe it, but you have to understand the whole character of both implicit and explicit conversions between types because this is one place where you're going to get a possibility of conversions. Very similar to conversions you get in an assignment expression where the left side expression is converted to the right side type. This is where it's saying it's a very important step, call-by-value. It's as if for n, remember that parameter n and we write inside the code action on n, well, if you substitute for n, an n local, as if it is what is used inside execution of the function with the first step being n local is assigned n. Notice, whatever n will be as an expression, that is going to have a value be n local. So n is going to be integer. We get an expression conversion, if whatever gets done there and then n local is what is used. N is unaffected. The n value is never changed even if as in our example, it seems to go to zero, but that's not what's going to zero. A local version of it is what's being changed, and that local version has no effect on the surrounding environment, on the environment from where it was called. The rest remains straightforward. The function body is then executed. We look for a return statement, and if return statement is encountered, the function exits to where the function was called, to where it was invoked. Called, invoked, same thing. If there's a return expression, remember in this case, our example, we have an integer function. So again, whatever the expression is, it has to be, if necessary, converted back to the type of the function, in this case an integer, and that's what gets used in the calling environment. For example, we could print the value of that function. Finally, if there is no return, it's as if a return was implicit in the last statement of the function code block. So even if when you don't see a return, you can imagine a return when you fall off the end of the code for that function. All right. So crucial, very important topic. Play with this idea. Try that particular function, write it up, run it, print various values, see that it all works as we've just described.