OK, so now it is time for us to really pick apart that Hello World program and kind of analyze it so
we can really see what every line is actually doing other than me just giving that basic explanation
of each line.
We haven't really learned about what all this stuff means, and although there's a lot going on there,
I think that it is simple enough for us to cover it in one lecture here.
So let's take a deep dive into this Hello world program.
So we're going to start from top to bottom, and I'm going to give the best explanation I can of each
line in the program.
So first off, we start out with that include thing, right?
It's a hashtag and then the word include.
And then there's a space, and then it says, I'll stream in between less than and greater, then sign.
So the include is something called the include directive.
And all this means is that it says go search for another file that has code in it.
And put the code that is in that file in our current file right here, where it says include.
And so it's in this actual case right here is talking about the i o stream file.
There's another C++ file.
It is actually kind of like where we installed the main GW, if you remember from that video for Windows,
where we installed the minimum new compiler collection, kind of where that got installed, it also
installed some of the standard C++ library, which includes this Io stream file that has code that we
can use.
And so what it does is Include says, I want to include the contents of this Io stream file in my code
so I can use stuff from it.
So says Go search for that and put the code that exists in that file right here and just insert all
of that code that would be in there.
There's a lot of code that comes from this i o stream file this kind of thing from the standard template
library.
So it's pretty cool that you can just include that and have access to a lot of functionality from this
file.
So, yeah, it's including in this particular case, it's including extreme, and that is something
that allows us to use this sea out and this in line down here as well as these operators, and we'll
be getting to that line soon enough.
So let's look at the next line.
This is called using a namespace.
So when you put this using namespace STD, it's just something that lets you use this out and inline
without having to put something called a scope resolution operator before it and put the particular
namespace.
You know, it says namespace STD.
That basically is, you know, related to this IO stream here, Io Stream is part of the standard template
library of C++.
And so if we don't want to have to use this in front of all of the things that we get from this.
I stream here, then we need to put something like using namespace STD.
It is possible to not have this line at all.
And before the column and inline, you could just put this STD Coleman call.
In that way, C++ would know, Oh, OK, you're trying to use something from this standard library of
stuff that comes with C++.
I understand now you put an STD call in calling before a see.
Now I know what this is.
I know where it's coming from.
So that's the only reason we put this is just so we can kind of be a little lazy and we don't have to
use this part right here in front of it.
It is sometimes considered bad practice to put this in code in C++, but nevertheless you will see throughout
the course that we sometimes just use it because we can and sometimes we won't use it.
We'll be getting deep into what a namespace really is later, because you don't have to always put using
namespace STD.
You can actually make your own name spaces and things like that.
But that's a little bit more of an advanced concept for later.
So right now, I'm just trying to explain it in terms of like how you can use it for the STV namespace
only.
So that's all you need to know about it for right now.
So this next line is us starting to define the main function.
So what is that?
We're talking about this line, this whole line up to here with this bracket.
So it says and space main with some empty parentheses and open and close parentheses.
And then we have an open curly brace.
So we're going to take a quick detour, actually.
I said main function and that kind of makes it necessary for me to just describe a little bit in general
what a function even is.
So I'm not going to go super in-depth to functions because we're going to have a separate part of the
course just on functions.
But I'm going to explain just enough.
So you kind of know what this main function is.
So what is a function of function is basically just a little sub program inside your whole program and
your file.
That does a specific task.
So an analogy for this would be like if you can think of your whole program as a factory, like maybe
a car factory.
The function would be similar to something in regards to an analogy, like a machine that just made
the wheels like it just does one specific thing like you make a function and it makes the wheels for
the car.
So something like that, you know, you can imagine it as a machine.
That's a part of the bigger picture.
You know, the whole factory makes cars, but it's made up of a bunch of different machines that make
the different pieces of the car so your program can be made up of a bunch of different functions that
handle a bunch of different tasks.
They each are assigned a specific thing to do some work to do for your program.
So quite often these functions, they take input data and then inside of the function, it will process
the data or do some sort of task that you assigned it.
You know, that task is just the code inside the function.
So inside here, the work that main is doing is pretty much this right here.
It's job that we've assigned it is to print out this Hello, my world, so.
Let's go back to here, so it processes the data or does some type of task that is just the code that's
inside of the curly braces, the open and close curly braces.
And then quite often functions also return some sort of output data.
So take something in, mess around with it, change it and put, you know, kind of pop something out.
So it's like you could think of this as you know that let's go back to this car factory analogy with
the machine that makes the wheels.
Let's say, like you give it the materials it needs to make the wheels.
So that's the input data.
You give it this material, it goes into the machine.
The machine does a bunch of fancy stuff.
You know, maybe it like melts down some metal and shape stuff.
I'm pretty sure this is not how car wheels are made, but you know, just for the sake of the analogy,
bear with me.
You know, it turns it into a wheel inside here and then it gives you a wheel.
So material goes in.
It makes the wheel wheel comes out.
So that's kind of like what the function the functions do, except that this is not always mandatory.
It can be just one or the other.
Maybe it does not take input data.
It might just, you know, return something to you.
Like you could just say, hey, function, you know, give me a random number or something, and it
would just come up with a random number and return that number to you.
Or you might say, Hey, I'm going to give you something.
And I just want you to take this thing and change it.
But I don't need any new thing back after you change.
I just want you to take this and change it.
And maybe it changes it and does stuff in here and you don't need anything back from it, from wherever
you.
Sent it, you know, you sent it from some location in the code, you sent it the input material.
And you just say, Hey, do stuff with this.
I don't need anything back, but I want you to do stuff with it because this thing needs to be modified
so it can be either or both can take input data and then mess with it and return stuff.
Or it can just take in stuff and mess with it, or it can not take anything, but it still does some
task and returns you something.
So any of those options?
So, like I said, there can be many functions in the C++ program.
You could have, you know, infinitely many functions.
But what we're focusing on now, since we're not really going over how to write our own functions,
we're just trying to explain what this is.
We're just focusing on main, the main function.
So the instructions in the main function are actually special member before I said, this is a special
name of the function.
It is actually the first instructions to be executed when your program runs.
So the main function is the entry point to your program.
So it'll come here first to main and then it will start running this first line here.
So first line to be run by the computer will be the first line in Maine as far as, like executing some
sort of statement.
Of course, we have this include up here.
That's something that happens during a pre kind of processing phase when the compilation process happens.
So but when the program's actually running being executed, it's going to come here first to do the
actual main work of your program and it will hit this first line.