Until this point we've only ever had our code in our main.
And I said before that main is what is called a function.
Well we can make our own functions as well.
So let's see how you can do that.
So the very first step always is to declare our function so that anything below can use it.
So we're in cellos are always going to have our declarations above mean usually near the top of the
file.
That's where I like to put them.
So let's take a look at this little bit.
So the first thing you'll see is what is called the return value of a function.
So here it's this weird thing called void and what void means in this case is that there is no return
value for this function.
It doesn't have to be or it could be something like an int or a char or any type you've seen so far.
But we'll talk about return values that later.
So the next thing is the name of the function and we get to choose what that name is.
So this name again remember that it's also an identifier so names have the same restrictions as variables
so you can have a.
So you have to have a letter as the first character but after that it can be digits or letters or underscores.
So for this course our names are always have capital letters as first letter of the function and each
subsequent word will also be capitalized.
But everything else will be lower case like this.
So the next part is the parentheses.
And this indicates the parameters or arguments of the function.
So parameters are variables that can be passed into the function from outside sources.
We'll be looking at this a bit later as well.
So since it's a statement there's always a semi-colon at the end so always remember that this declaration
is a statement.
So this whole line is called a the function signature.
So the function signature consists of the parameters the name of the function and the return type is
the return type.
K. so will be.
You'll see why I say Funt function signature and why a function signature is important in a leader lecture
in this section.
So the next thing we need to do is actually define this function.
So for our definition
we're just kind of say hello.
And notice that I'm rewriting the function signature here.
Same as above.
This K and we have the source code blocker statement block OK.
And this is where we actually define what the code should be for this function.
So all we're going to have here is a hello world that's it.
And so we've defined our function now.
So the last thing to do is just to call the function.
So all we need to do is actually say we don't need the return type anymore more we just have to say
print hello and then pass in whatever parameters we would have which we have none.
In this case and then the semi-colon.
OK.
So Main here its main function is considered the color of the print Telo function.
So just remember that anyone who calls this is what's called calling a function or using the function
right.
So this is what's called calling the function and Main is the caller.
And print hello would be considered the call Lee.
So if you ever hear me say the caller I'm really talking about the caller of the function.
So let's run this and see what happens.
So print out Hello world as we would expect.
So basically we defined our function.
And since Maine is the starting point man calls this function the control flow switches to this print
Telo function.
It does everything it needs to do and the code does all the steps.
There's only one in this case this number 26.
And then this prints hello world and then the control flow shifts back to main and it exits that way.
That's kind of how the flow of function calls work.
It's very important to understand.
And in this case it is very simple and doesn't really do much but it illustrates how functions really
work and so functions are really useful for logically breaking up the code into smaller and easier to
understand chunks.
And we'll be using them basically from now on.
And all of our games will be designed using functions.
So we'll be talking a lot more about functions in the future.
So in the next lecture I want to talk about parameters to functions.