Now let's talk about functions that can return values.
So let's see an example.
We're going to make a function called Square and all of this will do is square the number that we pass
into it.
And notice here that we have it at the start of the signature and it is the return type of the square
function.
So it's going to return an integer to the color of the square function.
So it's defined square here.
X and all this will do is return back to the caller.
The number that they passed in multiplied by itself.
And to do this we use this return keyword so return once it's executed then it will return the control
flow back to the caller.
So for example if we had more lines of code here K
these would never be executed because we already returned the control flow and this value right.
This this will evaluate to an integer and we'll return back to the caller.
So let's say here say
Square let's say 5 is
can we call it rate here and we can do this because Square really just evaluates to an integer.
So this whole thing will evaluate to basically this down here k.
And since square returns an integer you can just print out at integer just by calling the square function.
So it's just reminiscence the square 5 is 25.
It's not very surprising.
So we're talking about here with that return key word so say we had C out after the return.
If we run that.
So you will never actually see that because return returns the control flow of the program back up to
its caller.
So the caller is Main in this case and after this line it will go back up to here.
Ill print out this whole whole thing.
This square of five is twenty five.
And meanwhile continue on its merry way.
Kay so it will never do this.
So keep that in mind if you return something and you don't have some kind of condition or something
associated with it.
Nothing else after that will execute
an really return the return type can be any type we want so it is not limited to any type that we looked
at.
Right.
So and we'll see this a bit later as well.
So for now the return values will be limited to our basic types that we can over but later on you'll
see that all get into some more complicated types so in the next lecture I'm going to talk about some
more interesting things.