1
00:00:01,870 --> 00:00:10,570
So, like I said, it's a special function, and since it happens first, what's really going on is

2
00:00:10,570 --> 00:00:15,520
that it is actually called by the operating system of the computer.

3
00:00:16,000 --> 00:00:20,340
So, you know, like Windows or Mac, you have an operating system running.

4
00:00:20,350 --> 00:00:26,770
So when you run your program, the operating system is actually calling this originally.

5
00:00:27,070 --> 00:00:35,760
And then from Maine, you may or may not call other functions that would be you calling other functions.

6
00:00:35,770 --> 00:00:41,470
The operating system will call Maine, but in Maine, and that's where you might call other functions,

7
00:00:41,470 --> 00:00:43,630
and we're not implementing these other functions yet.

8
00:00:44,110 --> 00:00:46,320
But I just want to point out the difference between that.

9
00:00:46,330 --> 00:00:51,610
Maine is a special function because it gets called by the operating system, and it's also the first

10
00:00:51,610 --> 00:00:53,320
thing those are the things that make it special.

11
00:00:55,240 --> 00:00:58,120
And so, like I say, we were going to make our own functions later.

12
00:00:58,150 --> 00:01:02,890
But you just need to remember that this is the entry point of the program.

13
00:01:07,000 --> 00:01:12,340
So let's move on to the first line that is getting executed that we were talking about.

14
00:01:13,120 --> 00:01:19,930
So after we have our main with an open curly brace, we have stuff inside and this close curly brace

15
00:01:19,930 --> 00:01:21,170
finishes off the function.

16
00:01:21,190 --> 00:01:24,100
The first thing that's happening is this see out.

17
00:01:24,760 --> 00:01:26,640
So what is see out what we said?

18
00:01:26,650 --> 00:01:32,230
It's kind of coming from this Io stream that we included the code from, but we can't really see the

19
00:01:32,230 --> 00:01:32,530
code.

20
00:01:34,270 --> 00:01:36,670
So this is called a see out stream object.

21
00:01:39,590 --> 00:01:42,830
And then we have these interesting little things after it.

22
00:01:43,790 --> 00:01:46,250
And these are called insertion operators.

23
00:01:47,290 --> 00:01:52,570
So we have some here and some here and in the middle, we have something called a string.

24
00:01:53,110 --> 00:01:58,990
So between the devil quotes here we have some words and you notice before this is what printed out to

25
00:01:58,990 --> 00:01:59,590
the console.

26
00:01:59,590 --> 00:02:02,950
Whatever we had in between the devil course was what printed out.

27
00:02:05,260 --> 00:02:09,010
And then I will get to this in line in a second, but that's another part of the line.

28
00:02:10,210 --> 00:02:12,280
So what's up with the Seattle part?

29
00:02:12,310 --> 00:02:16,870
Seattle is a special word that comes from this library.

30
00:02:17,110 --> 00:02:17,890
I'll stream.

31
00:02:19,270 --> 00:02:23,770
Which is part of that standard standard template library, it's that other file is being included.

32
00:02:24,830 --> 00:02:29,000
So it lets us print text to the console, that's pretty much its purpose.

33
00:02:29,480 --> 00:02:31,490
We said that it was a stream object.

34
00:02:31,850 --> 00:02:33,510
So what is the stream object?

35
00:02:33,530 --> 00:02:41,720
It's basically something that you can just think of as like a stream of data allows for a stream of

36
00:02:41,720 --> 00:02:43,790
data to go from one place to another.

37
00:02:44,360 --> 00:02:48,590
So I like to think of it as something that can let a stream of data.

38
00:02:50,860 --> 00:02:59,560
Flow to the console, so whatever stream of data that you give it, it flows from here and kind of goes

39
00:02:59,560 --> 00:03:04,240
into this opening right here and then you notice their arrows are kind of pointing this way.

40
00:03:04,660 --> 00:03:06,430
And this is like console out.

41
00:03:07,810 --> 00:03:13,480
So hello, my world is basically getting siphoned through these little like floodgates here.

42
00:03:14,850 --> 00:03:17,430
And then it's going to the sea out.

43
00:03:19,220 --> 00:03:26,270
So I think that's a nice analogy, the floodgates for the stream and this hello world, which I actually

44
00:03:26,270 --> 00:03:32,870
have hello, my world in here is flowing through this opening out to the console, and I remember the

45
00:03:32,870 --> 00:03:36,050
console as this box that we had at the bottom of our editor.

46
00:03:36,560 --> 00:03:40,490
Or it was like technically in the terminal if we ran it in the terminal.

47
00:03:41,980 --> 00:03:45,730
So what's this thing that's flowing through here, though, the hell of my world?

48
00:03:46,120 --> 00:03:48,250
You said it was a stream, but what is the string?

49
00:03:48,700 --> 00:03:51,850
A string is something that we're also going to get into later.

50
00:03:51,850 --> 00:03:54,070
Just like the functions, we're going to go deeper into it.

51
00:03:54,070 --> 00:04:00,730
But right now, whenever you see anything that has double quotes surrounding it, like some text in

52
00:04:00,730 --> 00:04:01,000
here.

53
00:04:02,550 --> 00:04:09,600
It can be numbers or a text and a combination of those and spaces or special characters or anything

54
00:04:09,780 --> 00:04:14,640
that is something called a string, if it has double quotes around it and you see it in your program,

55
00:04:14,640 --> 00:04:17,610
it is going to be a string and it's a type of data.

56
00:04:17,670 --> 00:04:18,030
Right?

57
00:04:18,750 --> 00:04:20,280
A string is a type of data.

58
00:04:21,300 --> 00:04:27,150
Very, very soon we're going to get into data types and Patricia is going to go over data types with

59
00:04:27,150 --> 00:04:27,420
you.

60
00:04:28,290 --> 00:04:35,910
So I'm kind of just doing a very basic introduction to one of them right now, which is a string with

61
00:04:35,910 --> 00:04:36,720
these double quotes.

62
00:04:38,190 --> 00:04:39,540
And we'll get into that more later.

63
00:04:41,140 --> 00:04:46,600
So what is this thing at the end here, so I'm not going to spend a ton of time explaining this, but

64
00:04:46,600 --> 00:04:50,290
basically all it does is it just adds a new line to the output.

65
00:04:50,710 --> 00:04:56,410
And what I'm going to do is I'm actually going to show you kind of what happens when we get rid of it.

66
00:04:57,250 --> 00:04:58,750
So if I go here?

67
00:04:59,840 --> 00:05:02,330
I pull up my console, I have hello my world.

68
00:05:04,010 --> 00:05:16,550
So I go ahead and I save this and then I do a I'm on duty plus plus hello World Cup, and I'm going

69
00:05:16,550 --> 00:05:19,040
to do a show and I'm just going to call it.

70
00:05:19,610 --> 00:05:22,910
Hello, Dixie.

71
00:05:23,600 --> 00:05:24,770
And when pressed into.

72
00:05:27,370 --> 00:05:36,300
And I compile this and then I'm going to do and done slash hello, obstinate stone and slash Hello Don

73
00:05:36,340 --> 00:05:39,940
easy and a prince, hello, my world like that, right?

74
00:05:40,780 --> 00:05:48,220
Let's go back in here, and what I'm going to do now is I'm going to remove this in line if I remove

75
00:05:48,220 --> 00:05:48,940
the in line.

76
00:05:49,150 --> 00:05:59,080
I also have to remove the little floodgates, which are the insertion operator here, because that was

77
00:05:59,080 --> 00:05:59,920
for the in line.

78
00:05:59,920 --> 00:06:02,230
It was like the in line was flowing through this right.

79
00:06:02,680 --> 00:06:04,150
So I don't need those anymore.

80
00:06:04,150 --> 00:06:06,750
I actually can't have those since I deleted in line.

81
00:06:06,760 --> 00:06:12,850
I now need just this pair of this output insertion operator.

82
00:06:13,630 --> 00:06:15,400
So it's just going to do hell in my world.

83
00:06:15,410 --> 00:06:19,750
So let's see what happens now and I get get rid of that thing that as the new line.

84
00:06:24,740 --> 00:06:32,640
All right, so I'm going to compile this again, and then I'm going to run it, OK?

85
00:06:32,690 --> 00:06:34,910
You notice now there's no space right here.

86
00:06:35,180 --> 00:06:43,400
So when I did it before there was a there was a line and then there was basically also this extra line.

87
00:06:44,180 --> 00:06:45,650
It's just nice in this.

88
00:06:47,570 --> 00:06:53,210
Counsel right here in this terminal and this is command prompt, so seemed that it's just separating

89
00:06:53,210 --> 00:06:53,600
these.

90
00:06:54,590 --> 00:06:56,990
But if I was to go to.

91
00:06:59,450 --> 00:07:00,950
Let's say Bash.

92
00:07:02,980 --> 00:07:04,360
So if you're on Linux.

93
00:07:06,990 --> 00:07:11,730
And I run the Hello, sexy.

94
00:07:13,880 --> 00:07:14,870
You see what happens.

95
00:07:15,500 --> 00:07:22,820
It just backs it up right against the prompt here, which is kind of annoying like, you know, it's

96
00:07:22,820 --> 00:07:26,270
hard to read your stuff as printing and then you just have that sitting right there.

97
00:07:26,270 --> 00:07:30,980
So that's why it's kind of nice to have that.

98
00:07:31,940 --> 00:07:34,070
So I'm going to go ahead and add this back in.

99
00:07:36,170 --> 00:07:42,760
I do an hour there and I'm going to do it.

100
00:07:42,760 --> 00:07:52,190
So I have to retest this command because I'm now in bash, so I'm going to do the same thing.

101
00:07:57,820 --> 00:08:06,580
And now I'm going to run it, and now you notice that it prints out kind of nicely, so this added an

102
00:08:06,580 --> 00:08:08,860
extra little space for us by default.

103
00:08:08,890 --> 00:08:14,510
So even though I took it away, it came out similar to what this is, but it was kind of gross here,

104
00:08:14,510 --> 00:08:14,800
right?

105
00:08:15,100 --> 00:08:21,580
So I went ahead and added that, and now it comes out in between these prompts so we can actually see

106
00:08:21,580 --> 00:08:22,000
it better.

107
00:08:23,140 --> 00:08:25,960
So that's just something I wanted to point out.

108
00:08:26,440 --> 00:08:28,780
So I'm going to go back to the presentation here.

109
00:08:29,410 --> 00:08:31,780
So it just adds a new line to the output.

110
00:08:31,780 --> 00:08:32,950
That is what Intel does.

111
00:08:32,950 --> 00:08:37,810
It comes from the same Io stream thing we included up here as well.

112
00:08:39,970 --> 00:08:42,640
So now let's look at this last line right here.

113
00:08:43,240 --> 00:08:45,450
So it says return zero.

114
00:08:45,460 --> 00:08:48,640
So this is one of those return statements that I was talking about.

115
00:08:50,260 --> 00:08:56,290
So do you remember how we talked about functions potentially returning things after they perform their

116
00:08:56,290 --> 00:08:56,710
tasks?

117
00:08:56,710 --> 00:09:02,080
So we have that little diagram where stuff goes in, it performs an action and stuff goes out when stuff

118
00:09:02,080 --> 00:09:02,590
goes out.

119
00:09:02,590 --> 00:09:04,660
That was the returning part.

120
00:09:05,770 --> 00:09:08,320
So that's what this return zero is for.

121
00:09:08,440 --> 00:09:15,760
Main is returning a number which is zero back and where is it returning it back to?

122
00:09:15,820 --> 00:09:17,260
That's what is interesting.

123
00:09:17,260 --> 00:09:21,130
So the main function was originally called by the operating system.

124
00:09:22,550 --> 00:09:31,640
So when it returns zero, that's basically it saying that the program was able to finish and exit successfully.

125
00:09:32,570 --> 00:09:41,210
So it's returning that as a special code, an exit code back to the operating system and that basically

126
00:09:41,210 --> 00:09:45,650
says everything ran, you know, OK, we didn't have certain errors.

127
00:09:45,650 --> 00:09:53,450
You know, if you have anything other than zero that signifies something else, you know, zero is kind

128
00:09:53,450 --> 00:09:54,620
of this success code.

129
00:09:54,920 --> 00:09:58,130
So everything else would be considered kind of an error code.

130
00:09:58,640 --> 00:10:03,560
But the thing that you need to think about now is just the fact that the operating system called this

131
00:10:03,890 --> 00:10:11,390
and at the end returns zero is just returning this special zero exit code back to the operating system,

132
00:10:11,390 --> 00:10:12,200
and that's what it means.

133
00:10:12,860 --> 00:10:15,950
And previously, I mentioned that this is not 100 percent necessary.

134
00:10:16,220 --> 00:10:19,190
You don't have to put returns zero, but it is a convention.

135
00:10:19,200 --> 00:10:24,650
So I'm just keeping it in here because it kind of makes sense for when we're describing a lot of these

136
00:10:24,650 --> 00:10:25,460
programming things.

137
00:10:28,160 --> 00:10:35,570
So and very last things definitely remember that you need to put a closing curly brace at the end of

138
00:10:35,570 --> 00:10:36,680
the main function.

139
00:10:36,680 --> 00:10:44,090
So here we had an opening curly brace and after all, the code inside we have the close curly brace.

140
00:10:44,480 --> 00:10:50,780
So also an interesting thing is that you notice that I've been in dentin, like with a tab, the code

141
00:10:50,780 --> 00:10:52,820
that is inside of these braces.

142
00:10:53,540 --> 00:10:55,340
So that is not necessary.

143
00:10:56,270 --> 00:11:03,830
C++ would still run it if they were at different indentation levels or they had no indentation at all.

144
00:11:04,160 --> 00:11:10,580
But it's kind of good practice for readability and having clean code to indent things that are inside

145
00:11:10,580 --> 00:11:11,390
of a function.

146
00:11:12,650 --> 00:11:18,020
And we'll notice that we use indentation for other things besides functions in our code later on in

147
00:11:18,020 --> 00:11:18,530
the course.

148
00:11:18,980 --> 00:11:21,650
So it's kind of just a clean code, good practice thing.

149
00:11:23,580 --> 00:11:31,230
So just to reiterate, everything in between these curly braces is part of the main function.

150
00:11:31,770 --> 00:11:38,580
So you consider you can consider whatever Maine does to me, this stuff in here, it will.

151
00:11:39,820 --> 00:11:46,990
See out, which means cancel out if we can all remember that the hell of my world string to the console

152
00:11:46,990 --> 00:11:52,630
and then do an end line and then it will return zero to the operating system, they call it.

153
00:11:54,370 --> 00:11:57,970
So that is something important to remember.

154
00:11:58,660 --> 00:12:04,660
And also, one last thing to take away from this is the fact that we have these semicolons here.

155
00:12:04,660 --> 00:12:09,910
So pretty much everything that is a statement in C++.

156
00:12:09,920 --> 00:12:14,830
So not like this include, you know, which is kind of a pre processing thing.

157
00:12:16,310 --> 00:12:20,660
And not the actual function definition, which we have for main here.

158
00:12:21,350 --> 00:12:25,940
Everything that's not those is going to need to have a semicolon at the end.

159
00:12:27,520 --> 00:12:31,870
OK, so hopefully that was enough of a look into this.

160
00:12:31,900 --> 00:12:32,980
Hello, world.

161
00:12:33,310 --> 00:12:40,240
Hello, my world in this case program and you're able to understand what was happening.

162
00:12:40,870 --> 00:12:46,780
We're going to take a big step back in the next lectures and we're going to be looking at some very

163
00:12:46,780 --> 00:12:49,270
primitive data types and things like that.

164
00:12:49,600 --> 00:12:56,980
So we're kind of going to start from ground zero, but we want to know enough about how to run a C++

165
00:12:56,980 --> 00:13:00,850
program to be able to add some more stuff in between these curly braces.

166
00:13:00,880 --> 00:13:09,100
So the next little bit of the course is going to be us using this kind of as a template to be able to

167
00:13:09,100 --> 00:13:10,910
add some more stuff in between here.

168
00:13:10,910 --> 00:13:16,370
And we're not just going to see out Hello my world for every program right or see out.

169
00:13:16,390 --> 00:13:18,550
We're not just going to put something else between.

170
00:13:19,830 --> 00:13:25,050
Double quotes, because, you know, that's kind of a boring program, we're only just printing words

171
00:13:25,050 --> 00:13:28,680
out to or words or numbers or wherever we put in between here out to the console.

172
00:13:29,550 --> 00:13:36,630
We're going to try and print out some other data types that maybe aren't strings, and we're going to

173
00:13:36,630 --> 00:13:40,380
look at what those data types are and then we're going to try and make some code that actually does

174
00:13:40,380 --> 00:13:41,850
some more interesting stuff.

175
00:13:42,720 --> 00:13:46,170
OK, so with that, I will see you in the next lecture.
