1
00:00:00,830 --> 00:00:10,940
OK, so now it is time for us to really pick apart that Hello World program and kind of analyze it so

2
00:00:10,940 --> 00:00:18,590
we can really see what every line is actually doing other than me just giving that basic explanation

3
00:00:18,590 --> 00:00:19,370
of each line.

4
00:00:19,370 --> 00:00:25,220
We haven't really learned about what all this stuff means, and although there's a lot going on there,

5
00:00:25,610 --> 00:00:31,670
I think that it is simple enough for us to cover it in one lecture here.

6
00:00:31,880 --> 00:00:34,550
So let's take a deep dive into this Hello world program.

7
00:00:36,220 --> 00:00:41,950
So we're going to start from top to bottom, and I'm going to give the best explanation I can of each

8
00:00:41,950 --> 00:00:43,210
line in the program.

9
00:00:44,350 --> 00:00:48,240
So first off, we start out with that include thing, right?

10
00:00:48,250 --> 00:00:50,980
It's a hashtag and then the word include.

11
00:00:51,580 --> 00:00:57,850
And then there's a space, and then it says, I'll stream in between less than and greater, then sign.

12
00:00:59,930 --> 00:01:04,940
So the include is something called the include directive.

13
00:01:06,070 --> 00:01:14,950
And all this means is that it says go search for another file that has code in it.

14
00:01:15,780 --> 00:01:24,570
And put the code that is in that file in our current file right here, where it says include.

15
00:01:24,960 --> 00:01:32,610
And so it's in this actual case right here is talking about the i o stream file.

16
00:01:32,610 --> 00:01:35,130
There's another C++ file.

17
00:01:36,020 --> 00:01:43,040
It is actually kind of like where we installed the main GW, if you remember from that video for Windows,

18
00:01:43,940 --> 00:01:50,840
where we installed the minimum new compiler collection, kind of where that got installed, it also

19
00:01:50,840 --> 00:02:00,290
installed some of the standard C++ library, which includes this Io stream file that has code that we

20
00:02:00,290 --> 00:02:01,020
can use.

21
00:02:01,040 --> 00:02:09,260
And so what it does is Include says, I want to include the contents of this Io stream file in my code

22
00:02:09,260 --> 00:02:10,820
so I can use stuff from it.

23
00:02:11,540 --> 00:02:17,870
So says Go search for that and put the code that exists in that file right here and just insert all

24
00:02:17,870 --> 00:02:19,040
of that code that would be in there.

25
00:02:19,040 --> 00:02:28,160
There's a lot of code that comes from this i o stream file this kind of thing from the standard template

26
00:02:28,160 --> 00:02:29,030
library.

27
00:02:30,110 --> 00:02:38,030
So it's pretty cool that you can just include that and have access to a lot of functionality from this

28
00:02:38,030 --> 00:02:38,600
file.

29
00:02:40,380 --> 00:02:45,750
So, yeah, it's including in this particular case, it's including extreme, and that is something

30
00:02:45,750 --> 00:02:53,220
that allows us to use this sea out and this in line down here as well as these operators, and we'll

31
00:02:53,220 --> 00:02:54,870
be getting to that line soon enough.

32
00:02:58,350 --> 00:02:59,940
So let's look at the next line.

33
00:03:00,480 --> 00:03:03,840
This is called using a namespace.

34
00:03:07,070 --> 00:03:15,200
So when you put this using namespace STD, it's just something that lets you use this out and inline

35
00:03:15,680 --> 00:03:22,730
without having to put something called a scope resolution operator before it and put the particular

36
00:03:22,730 --> 00:03:23,400
namespace.

37
00:03:23,420 --> 00:03:25,400
You know, it says namespace STD.

38
00:03:27,380 --> 00:03:35,210
That basically is, you know, related to this IO stream here, Io Stream is part of the standard template

39
00:03:35,210 --> 00:03:38,090
library of C++.

40
00:03:40,100 --> 00:03:46,640
And so if we don't want to have to use this in front of all of the things that we get from this.

41
00:03:47,640 --> 00:03:52,560
I stream here, then we need to put something like using namespace STD.

42
00:03:54,330 --> 00:03:57,750
It is possible to not have this line at all.

43
00:03:58,530 --> 00:04:03,570
And before the column and inline, you could just put this STD Coleman call.

44
00:04:03,570 --> 00:04:11,520
In that way, C++ would know, Oh, OK, you're trying to use something from this standard library of

45
00:04:11,520 --> 00:04:14,040
stuff that comes with C++.

46
00:04:14,970 --> 00:04:18,510
I understand now you put an STD call in calling before a see.

47
00:04:18,750 --> 00:04:20,180
Now I know what this is.

48
00:04:20,190 --> 00:04:21,660
I know where it's coming from.

49
00:04:22,730 --> 00:04:29,030
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

50
00:04:29,030 --> 00:04:31,760
use this part right here in front of it.

51
00:04:32,640 --> 00:04:40,170
It is sometimes considered bad practice to put this in code in C++, but nevertheless you will see throughout

52
00:04:40,170 --> 00:04:47,010
the course that we sometimes just use it because we can and sometimes we won't use it.

53
00:04:47,340 --> 00:04:53,730
We'll be getting deep into what a namespace really is later, because you don't have to always put using

54
00:04:53,730 --> 00:04:54,840
namespace STD.

55
00:04:55,680 --> 00:04:59,670
You can actually make your own name spaces and things like that.

56
00:05:00,030 --> 00:05:03,690
But that's a little bit more of an advanced concept for later.

57
00:05:03,720 --> 00:05:12,120
So right now, I'm just trying to explain it in terms of like how you can use it for the STV namespace

58
00:05:12,120 --> 00:05:12,600
only.

59
00:05:13,290 --> 00:05:15,650
So that's all you need to know about it for right now.

60
00:05:18,350 --> 00:05:25,220
So this next line is us starting to define the main function.

61
00:05:25,940 --> 00:05:27,030
So what is that?

62
00:05:27,050 --> 00:05:30,770
We're talking about this line, this whole line up to here with this bracket.

63
00:05:31,280 --> 00:05:38,690
So it says and space main with some empty parentheses and open and close parentheses.

64
00:05:39,230 --> 00:05:41,990
And then we have an open curly brace.

65
00:05:44,880 --> 00:05:47,590
So we're going to take a quick detour, actually.

66
00:05:48,450 --> 00:05:57,210
I said main function and that kind of makes it necessary for me to just describe a little bit in general

67
00:05:57,450 --> 00:05:59,490
what a function even is.

68
00:06:00,090 --> 00:06:07,170
So I'm not going to go super in-depth to functions because we're going to have a separate part of the

69
00:06:07,170 --> 00:06:09,390
course just on functions.

70
00:06:09,390 --> 00:06:11,880
But I'm going to explain just enough.

71
00:06:11,880 --> 00:06:15,060
So you kind of know what this main function is.

72
00:06:15,900 --> 00:06:25,680
So what is a function of function is basically just a little sub program inside your whole program and

73
00:06:25,680 --> 00:06:26,310
your file.

74
00:06:27,660 --> 00:06:29,580
That does a specific task.

75
00:06:29,940 --> 00:06:37,350
So an analogy for this would be like if you can think of your whole program as a factory, like maybe

76
00:06:37,350 --> 00:06:38,700
a car factory.

77
00:06:39,480 --> 00:06:46,350
The function would be similar to something in regards to an analogy, like a machine that just made

78
00:06:46,350 --> 00:06:52,710
the wheels like it just does one specific thing like you make a function and it makes the wheels for

79
00:06:52,710 --> 00:06:53,190
the car.

80
00:06:53,970 --> 00:06:57,330
So something like that, you know, you can imagine it as a machine.

81
00:06:57,330 --> 00:07:00,360
That's a part of the bigger picture.

82
00:07:00,360 --> 00:07:08,580
You know, the whole factory makes cars, but it's made up of a bunch of different machines that make

83
00:07:08,580 --> 00:07:16,260
the different pieces of the car so your program can be made up of a bunch of different functions that

84
00:07:16,260 --> 00:07:19,260
handle a bunch of different tasks.

85
00:07:19,380 --> 00:07:25,140
They each are assigned a specific thing to do some work to do for your program.

86
00:07:27,120 --> 00:07:37,980
So quite often these functions, they take input data and then inside of the function, it will process

87
00:07:37,980 --> 00:07:41,790
the data or do some sort of task that you assigned it.

88
00:07:41,790 --> 00:07:45,420
You know, that task is just the code inside the function.

89
00:07:46,140 --> 00:07:53,400
So inside here, the work that main is doing is pretty much this right here.

90
00:07:54,950 --> 00:08:05,810
It's job that we've assigned it is to print out this Hello, my world, so.

91
00:08:10,770 --> 00:08:16,410
Let's go back to here, so it processes the data or does some type of task that is just the code that's

92
00:08:16,410 --> 00:08:21,690
inside of the curly braces, the open and close curly braces.

93
00:08:23,210 --> 00:08:29,300
And then quite often functions also return some sort of output data.

94
00:08:29,510 --> 00:08:38,510
So take something in, mess around with it, change it and put, you know, kind of pop something out.

95
00:08:39,320 --> 00:08:48,050
So it's like you could think of this as you know that let's go back to this car factory analogy with

96
00:08:48,050 --> 00:08:50,150
the machine that makes the wheels.

97
00:08:50,720 --> 00:08:54,800
Let's say, like you give it the materials it needs to make the wheels.

98
00:08:55,160 --> 00:08:56,660
So that's the input data.

99
00:08:57,200 --> 00:08:59,860
You give it this material, it goes into the machine.

100
00:08:59,870 --> 00:09:02,030
The machine does a bunch of fancy stuff.

101
00:09:02,030 --> 00:09:05,210
You know, maybe it like melts down some metal and shape stuff.

102
00:09:05,480 --> 00:09:11,210
I'm pretty sure this is not how car wheels are made, but you know, just for the sake of the analogy,

103
00:09:11,210 --> 00:09:11,930
bear with me.

104
00:09:12,750 --> 00:09:19,460
You know, it turns it into a wheel inside here and then it gives you a wheel.

105
00:09:20,240 --> 00:09:21,980
So material goes in.

106
00:09:21,980 --> 00:09:24,290
It makes the wheel wheel comes out.

107
00:09:25,550 --> 00:09:32,300
So that's kind of like what the function the functions do, except that this is not always mandatory.

108
00:09:32,870 --> 00:09:34,670
It can be just one or the other.

109
00:09:34,890 --> 00:09:37,720
Maybe it does not take input data.

110
00:09:39,900 --> 00:09:43,770
It might just, you know, return something to you.

111
00:09:44,580 --> 00:09:52,680
Like you could just say, hey, function, you know, give me a random number or something, and it

112
00:09:52,680 --> 00:09:56,220
would just come up with a random number and return that number to you.

113
00:09:56,790 --> 00:10:00,900
Or you might say, Hey, I'm going to give you something.

114
00:10:02,220 --> 00:10:05,370
And I just want you to take this thing and change it.

115
00:10:05,790 --> 00:10:09,260
But I don't need any new thing back after you change.

116
00:10:09,270 --> 00:10:11,130
I just want you to take this and change it.

117
00:10:11,130 --> 00:10:18,420
And maybe it changes it and does stuff in here and you don't need anything back from it, from wherever

118
00:10:18,420 --> 00:10:18,900
you.

119
00:10:20,600 --> 00:10:25,310
Sent it, you know, you sent it from some location in the code, you sent it the input material.

120
00:10:25,640 --> 00:10:27,530
And you just say, Hey, do stuff with this.

121
00:10:27,530 --> 00:10:31,670
I don't need anything back, but I want you to do stuff with it because this thing needs to be modified

122
00:10:32,000 --> 00:10:38,300
so it can be either or both can take input data and then mess with it and return stuff.

123
00:10:38,600 --> 00:10:45,500
Or it can just take in stuff and mess with it, or it can not take anything, but it still does some

124
00:10:45,500 --> 00:10:47,450
task and returns you something.

125
00:10:47,780 --> 00:10:48,950
So any of those options?

126
00:10:50,940 --> 00:10:55,200
So, like I said, there can be many functions in the C++ program.

127
00:10:55,260 --> 00:10:58,860
You could have, you know, infinitely many functions.

128
00:10:59,310 --> 00:11:05,120
But what we're focusing on now, since we're not really going over how to write our own functions,

129
00:11:05,130 --> 00:11:07,650
we're just trying to explain what this is.

130
00:11:08,220 --> 00:11:10,980
We're just focusing on main, the main function.

131
00:11:11,880 --> 00:11:17,700
So the instructions in the main function are actually special member before I said, this is a special

132
00:11:17,700 --> 00:11:18,960
name of the function.

133
00:11:19,500 --> 00:11:25,140
It is actually the first instructions to be executed when your program runs.

134
00:11:25,500 --> 00:11:29,100
So the main function is the entry point to your program.

135
00:11:30,120 --> 00:11:35,520
So it'll come here first to main and then it will start running this first line here.

136
00:11:36,480 --> 00:11:43,620
So first line to be run by the computer will be the first line in Maine as far as, like executing some

137
00:11:43,620 --> 00:11:44,820
sort of statement.

138
00:11:45,810 --> 00:11:48,510
Of course, we have this include up here.

139
00:11:49,230 --> 00:11:59,310
That's something that happens during a pre kind of processing phase when the compilation process happens.

140
00:11:59,670 --> 00:12:04,890
So but when the program's actually running being executed, it's going to come here first to do the

141
00:12:04,890 --> 00:12:09,690
actual main work of your program and it will hit this first line.
