1
00:00:01,140 --> 00:00:09,510
All right, so moving on to a big new topic, we are now going to talk about our first type of container

2
00:00:09,510 --> 00:00:14,460
in C++ and that will be something called an array.

3
00:00:14,760 --> 00:00:22,350
So I have admitted the title screen here, but we're going to get right into it and define what an array

4
00:00:22,350 --> 00:00:22,830
is.

5
00:00:23,460 --> 00:00:30,510
So an array is a container that can hold multiple values of the same data type.

6
00:00:31,350 --> 00:00:33,880
It has a fixed size.

7
00:00:34,230 --> 00:00:40,860
It is contiguous and memory the same thing as saying it is continuous like a chunk.

8
00:00:41,820 --> 00:00:43,500
It is homogenous.

9
00:00:43,980 --> 00:00:49,980
Accessing elements in an array is done through sub scripting, and we will get into that and I'll show

10
00:00:49,980 --> 00:00:50,820
you what that means.

11
00:00:51,660 --> 00:00:58,540
And at the moment of creation of an array, a chunk of that contiguous memory is put aside for the entire.

12
00:00:58,790 --> 00:01:05,520
So this is us when we define it in our program, that is what happens in the memory.

13
00:01:05,520 --> 00:01:11,220
When we are running the program, there's going to be access to that entire contiguous block of memory

14
00:01:11,220 --> 00:01:12,030
that we have defined.

15
00:01:14,450 --> 00:01:17,250
So how to declare an era?

16
00:01:18,140 --> 00:01:26,120
So you notice here on the left, we have the data types so similar to how we would make a variable rate,

17
00:01:26,130 --> 00:01:33,740
we need to first put the data types so this could be in float devel, char string, etcetera, then

18
00:01:33,740 --> 00:01:37,100
we have the name of our array variable.

19
00:01:37,370 --> 00:01:39,380
So this will be the name of the array.

20
00:01:40,590 --> 00:01:48,000
And immediately after that, we need to put some brackets here, some square brackets, and inside of

21
00:01:48,000 --> 00:01:54,650
there, we need to declare the size decorator, which is how many elements are array will have.

22
00:01:54,660 --> 00:01:58,590
So how many things will we have in our array, for example?

23
00:01:58,620 --> 00:01:59,570
This was an integer.

24
00:01:59,580 --> 00:02:02,580
How many integers are we going to be storing in this array?

25
00:02:02,790 --> 00:02:05,220
So this all needs to be declared a front.

26
00:02:07,750 --> 00:02:10,870
So let's take a look at how this might look in memory.

27
00:02:11,260 --> 00:02:14,320
So an example is an array with seven elements.

28
00:02:14,860 --> 00:02:19,510
We need to define this as a constant size.

29
00:02:20,080 --> 00:02:27,850
So you could just put the number seven here, but we are here defining a variable that is a constant.

30
00:02:27,860 --> 00:02:29,950
So it's something that's not going to change.

31
00:02:30,430 --> 00:02:35,560
It has to be set and the data type is in and we call it the size.

32
00:02:36,160 --> 00:02:40,270
And so this seven is essentially being stored here for the size decorator.

33
00:02:40,840 --> 00:02:45,240
And remember, on the previous page, we said data type the name of the array.

34
00:02:45,250 --> 00:02:51,130
So like the array variable is going to have a name and then the size decorators zone with these square

35
00:02:51,130 --> 00:02:51,850
brackets, right?

36
00:02:51,850 --> 00:02:53,260
So that's what's happening right here.

37
00:02:53,710 --> 00:02:56,260
We have a type is the data type as integer.

38
00:02:56,320 --> 00:02:58,480
We're calling it my array as a variable name.

39
00:02:58,900 --> 00:03:02,800
We have some square brackets and then we're putting sides here, which is essentially just that number

40
00:03:02,800 --> 00:03:03,190
seven.

41
00:03:04,250 --> 00:03:05,560
What does it look like, though?

42
00:03:05,720 --> 00:03:10,640
That's what I wanted to show was here are those addresses that I just talked about.

43
00:03:10,650 --> 00:03:12,080
So here this is a little different.

44
00:03:12,770 --> 00:03:15,010
These are you seen 12 digits here.

45
00:03:15,020 --> 00:03:24,350
So this could be representative of a 64 bit address, but it's only showing the 12 hex places right

46
00:03:24,350 --> 00:03:24,620
there.

47
00:03:25,160 --> 00:03:30,620
But you noticed that the red part here shows the difference in the bytes as we go up.

48
00:03:30,860 --> 00:03:32,690
Remember these little parking spaces?

49
00:03:33,440 --> 00:03:35,540
They're kind of upset, so we're counting up.

50
00:03:36,440 --> 00:03:38,950
So let's take a look at that and what this really means here.

51
00:03:38,960 --> 00:03:44,060
So we have a contiguous block, so contiguous chunk here.

52
00:03:44,090 --> 00:03:47,930
We're having a bunch of integers stored at these question marks in this example.

53
00:03:49,640 --> 00:03:58,100
Here we have the labeled location of our like little parking spot we were talking about in memory.

54
00:03:59,120 --> 00:04:01,460
This first one has a read zero on the end.

55
00:04:01,940 --> 00:04:03,200
We're counting up.

56
00:04:03,800 --> 00:04:05,500
So let's go to the next space.

57
00:04:05,840 --> 00:04:09,590
Right to the right of it, we noticed that this changed from zero to four.

58
00:04:09,620 --> 00:04:11,180
Well, why does it do that?

59
00:04:11,510 --> 00:04:21,680
That is because like, for example, for a 64 bit Windows application, an integer would be four bytes.

60
00:04:22,790 --> 00:04:27,530
So that's why we are counting up from zero to four here.

61
00:04:28,760 --> 00:04:36,120
You know, as it goes from four to eight and then it goes to sea and then 10 and 14 and 18, so it's

62
00:04:36,120 --> 00:04:38,310
going up by four each time.

63
00:04:40,220 --> 00:04:42,230
You also should notice that there are.

64
00:04:43,490 --> 00:04:48,890
One, so one, two, three, four, five, six, seven spots here.

65
00:04:49,670 --> 00:04:55,460
But you notice in this example that we start at Element zero, we're not calling this element one.

66
00:04:56,060 --> 00:04:59,450
So we are going to talk about that in just a moment.

67
00:05:02,430 --> 00:05:10,110
So more things about the raid declaration, like I mentioned, we must know the size before we declare

68
00:05:10,110 --> 00:05:10,890
the array.

69
00:05:11,700 --> 00:05:15,960
The size variable must be a constant because the array size cannot change.

70
00:05:15,960 --> 00:05:22,290
That's why you noticed in this example, it said Konst, and size equals seven instead of just end size

71
00:05:22,290 --> 00:05:23,070
equals seven.

72
00:05:24,090 --> 00:05:27,510
We also could have just put the number seven down here.

73
00:05:27,510 --> 00:05:28,980
With this size variable is.

74
00:05:30,390 --> 00:05:34,890
But the point is that the science cannot change, so that's the important bit.

75
00:05:36,000 --> 00:05:42,960
So once declared, an array will have the same size until the program finishes, hence that fixed size.

76
00:05:45,680 --> 00:05:53,150
So if you do in a raid, a declaration without the initialization, so you're not really having some

77
00:05:53,150 --> 00:05:59,480
sort of actual data to the right of this that you're saying is in there, you're just declaring it.

78
00:05:59,840 --> 00:06:04,370
And you might add stuff into the spots in the array later than you would do it like this.

79
00:06:04,380 --> 00:06:10,910
So just like in the previous example, we say constant and we're seeing signs already this time equals

80
00:06:10,910 --> 00:06:11,390
five.

81
00:06:11,930 --> 00:06:13,310
We must know the type of data.

82
00:06:13,310 --> 00:06:19,790
So we say and my array and we put South Array in here, but we're not explicitly saying what is stored

83
00:06:19,790 --> 00:06:20,150
there.

84
00:06:20,150 --> 00:06:22,640
So we kind of just have these question marks, right?

85
00:06:22,640 --> 00:06:30,140
We have all this space allocated for us in this contiguous zone, but we don't know what stored there

86
00:06:30,140 --> 00:06:30,410
yet.

87
00:06:32,120 --> 00:06:35,660
So that means the array elements will be initialized to garbage in this case.

88
00:06:35,900 --> 00:06:41,690
It's just kind of whatever's in that section of memory because we haven't really defined what that is

89
00:06:41,930 --> 00:06:42,680
in this case.

90
00:06:44,910 --> 00:06:46,700
So here's another example.

91
00:06:46,740 --> 00:06:51,900
We have an array with five elements, this was like the previous example here.

92
00:06:52,440 --> 00:06:59,670
So if we declared it like this in our code, we said here is the size and here is us making the array.

93
00:06:59,700 --> 00:07:04,440
We're just declaring the array, the data type, the variable name and the size and the brackets.

94
00:07:05,640 --> 00:07:07,860
Then it would be something like this in memory.

95
00:07:08,130 --> 00:07:16,290
We're still using an inch, so you notice that we're counting up in fours here in Hex, and once again

96
00:07:16,290 --> 00:07:20,330
it's starting at zero, going up to four.

97
00:07:20,370 --> 00:07:22,050
So we have or sorry, five.

98
00:07:22,650 --> 00:07:23,600
So it goes up to four.

99
00:07:23,760 --> 00:07:26,330
We have five spots one two three four five.

100
00:07:26,340 --> 00:07:28,170
That's because we said the size was fine.

101
00:07:29,810 --> 00:07:35,150
So here is us defining exactly what is going to be stored there.

102
00:07:35,180 --> 00:07:39,440
Unlike the previous example, we kind of cut it off right here and we just put a semicolon.

103
00:07:40,550 --> 00:07:45,860
So if we have a list of numbers that we want to put right next to each other, list of integers.

104
00:07:46,870 --> 00:07:48,190
One, two, three and four.

105
00:07:49,000 --> 00:07:54,310
Then we can do kind of what we did before, but we can also add this little bit on the right.

106
00:07:54,970 --> 00:08:01,660
So in this example, we'll say constant size equals four because we have four elements that we want

107
00:08:01,660 --> 00:08:02,870
to be in the array, right?

108
00:08:02,920 --> 00:08:04,360
One two three four.

109
00:08:05,380 --> 00:08:06,940
So we do what we did before.

110
00:08:07,300 --> 00:08:13,720
But then, rather than finishing it off with a semicolon we say equals and then we use the curly braces.

111
00:08:14,230 --> 00:08:19,990
And in between the curly braces, we write down a list, a comma separated list of the elements that

112
00:08:19,990 --> 00:08:21,760
we want in the array.

113
00:08:23,250 --> 00:08:29,250
And notice that in this case, we have put we've said that the size is four and we have put four things

114
00:08:29,250 --> 00:08:31,740
inside of the curly braces here.

115
00:08:32,160 --> 00:08:33,900
So one, two three four.

116
00:08:34,800 --> 00:08:37,800
So now it'll be looking like this in the memory.

117
00:08:38,250 --> 00:08:44,820
So rather than having the question marks here, we see we have one two three four things.

118
00:08:45,460 --> 00:08:46,260
They're integers.

119
00:08:46,260 --> 00:08:52,110
So we notice that the addresses that each one of these are stored at is kind of counting up sequentially

120
00:08:52,110 --> 00:08:55,050
one two three four by four each time.

121
00:08:55,060 --> 00:08:58,440
So two zero four eight c. as far as the Hex.

122
00:09:00,530 --> 00:09:06,500
And you actually are having the things in this list represented here in one contiguous block of memory.

123
00:09:08,710 --> 00:09:16,450
So another thing that we can do is define the array explicitly with values, but only partially so this

124
00:09:16,450 --> 00:09:18,910
would be called partial array initialization.

125
00:09:19,850 --> 00:09:24,240
So when you initialize an array, you don't necessarily have to initialize all of its elements.

126
00:09:24,260 --> 00:09:30,920
You can just initialize the first few elements so the array elements will be initialized in order starting

127
00:09:30,920 --> 00:09:33,530
from position zero, which is the first position.

128
00:09:33,530 --> 00:09:34,400
The first thing.

129
00:09:34,970 --> 00:09:37,580
Onwards to as many elements as you are providing.

130
00:09:38,150 --> 00:09:43,340
The rest of the elements, though, will be initialized to something depending on the data type.

131
00:09:43,480 --> 00:09:46,400
An integer will be initialized to zero.

132
00:09:47,820 --> 00:09:56,130
Things like string or A will be initialized to what they respectively will be based on the C++ compiler

133
00:09:56,130 --> 00:09:56,820
and the language.

134
00:09:58,170 --> 00:09:59,490
So here we have consent.

135
00:09:59,490 --> 00:10:00,660
Size equals 10.

136
00:10:01,680 --> 00:10:09,600
So that means that we have set aside a contiguous block of memory with 10 parking spots.

137
00:10:10,050 --> 00:10:10,470
All right.

138
00:10:11,940 --> 00:10:18,090
But you notice here that we're not giving it 10 numbers to put in there, we're saying zero one two

139
00:10:18,090 --> 00:10:19,280
three four five.

140
00:10:19,290 --> 00:10:26,100
So that's six numbers, right one two three four five six things comma separated in between the curly

141
00:10:26,100 --> 00:10:28,560
braces, but this is the number 10 right here.

142
00:10:28,570 --> 00:10:29,760
So what happens?

143
00:10:30,180 --> 00:10:33,960
Well, let's take a look at what the memory will look like.

144
00:10:35,720 --> 00:10:41,990
So we notice we have a six or six things right here and this one, we've actually added.

145
00:10:42,380 --> 00:10:44,900
So this actually has a little typo here.

146
00:10:44,900 --> 00:10:47,600
We have an actual number six as well.

147
00:10:48,140 --> 00:10:51,080
So you can just pretend I have a comma and a six there.

148
00:10:51,080 --> 00:10:52,640
So it's actually seven things.

149
00:10:53,660 --> 00:10:55,220
So let's take a look right here.

150
00:10:56,650 --> 00:10:59,860
So same thing with China by force, because this is integers, right?

151
00:11:00,670 --> 00:11:08,050
But we have zero one two three four five six, and that was all we provided when I said, there's a

152
00:11:08,050 --> 00:11:13,570
little table here, so you can just imagine there's a comma and a six before the curly brace closes.

153
00:11:15,000 --> 00:11:21,990
But we said that it was 10, right, so the last three things are just initialized to zero since we

154
00:11:21,990 --> 00:11:24,870
said that the array was going to hold integers.

155
00:11:24,930 --> 00:11:30,780
They're just kind of considering this as the empty version of an integer, right?

156
00:11:30,810 --> 00:11:35,730
It's just the basic thing is is zero if you're talking about integers.

157
00:11:36,750 --> 00:11:41,580
So we have one two three four five six seven eight nine 10 things.

158
00:11:42,240 --> 00:11:46,080
Only seven were provided in that little initialize or list.

159
00:11:46,990 --> 00:11:53,650
So, yeah, only seven were provided, so the last three of that 10 are going to be automatically defined

160
00:11:53,650 --> 00:11:56,200
as zero since we said it was type integer.

161
00:12:00,180 --> 00:12:07,650
So array declaration using implicit resizing, this means that you are not providing a size in here

162
00:12:07,680 --> 00:12:14,160
and you must know all the elements that you want to store in the array beforehand so that you need to

163
00:12:14,160 --> 00:12:16,800
put this curly brace list no matter what.

164
00:12:18,400 --> 00:12:23,860
And in a race initialization list, cannot have more values than the array has elements.

165
00:12:25,770 --> 00:12:33,900
I think cannot exceed that the size no longer has to be declared, but it's known by you as in you provide

166
00:12:33,930 --> 00:12:36,270
the literal list of stuff here.

167
00:12:36,280 --> 00:12:41,490
So that's why it is possible to leave this blank in between square brackets where we would put the size

168
00:12:41,490 --> 00:12:42,150
decorator.

169
00:12:43,140 --> 00:12:50,970
But instead, we are using this explicit initialization list here with these curly braces and providing

170
00:12:50,970 --> 00:12:51,930
the numbers.

171
00:12:54,300 --> 00:12:58,260
So let's move on to how these are actually labeled.

172
00:12:58,500 --> 00:13:04,530
The positions inside of this array and how do we actually access things inside the array once we've

173
00:13:04,530 --> 00:13:05,040
declared?

174
00:13:05,220 --> 00:13:07,230
So let's look at this example right here.

175
00:13:07,950 --> 00:13:14,490
The previous example where we didn't really provide a size, but the array is going to store one two

176
00:13:14,490 --> 00:13:21,330
three four in each one of those parking spots because we've explicitly defined it in this list between

177
00:13:21,330 --> 00:13:22,710
the curly braces right here.

178
00:13:23,310 --> 00:13:32,160
So rolling forward with that example, the positioning of these arrays always starts counting from position

179
00:13:32,160 --> 00:13:32,640
zero.

180
00:13:32,640 --> 00:13:41,040
So if we want to refer to what thing is stored at what parking spot and we're not using the actual hex

181
00:13:41,040 --> 00:13:46,980
addresses, we're just talking to one another and saying, well, what in your array at the.

182
00:13:48,180 --> 00:13:53,400
First position, we're not really going to say first position, we're going to say the zeroth position,

183
00:13:53,400 --> 00:13:55,290
that's what should represent the first thing.

184
00:13:55,290 --> 00:13:57,390
So we start counting from zero.

185
00:13:59,470 --> 00:14:03,500
So you notice here, if we have that example with one, two, three four.

186
00:14:04,000 --> 00:14:09,820
The first thing is it position zero, second thing, position one, third thing, position two and fourth

187
00:14:09,820 --> 00:14:10,990
thing and position three.

188
00:14:11,350 --> 00:14:18,970
So there are four items in here, but we're counting them and labeling them kind of imaginatively as

189
00:14:19,150 --> 00:14:22,000
items zero item one, item two and three.

190
00:14:24,190 --> 00:14:29,380
So this provides you a way to access each element of the array based on the position it occupies.

191
00:14:29,830 --> 00:14:30,940
And how do we do that?

192
00:14:30,970 --> 00:14:38,860
Well, since this is at position zero, we're going to use the name of the array and then we're going

193
00:14:38,860 --> 00:14:44,920
to use square brackets and in between the square brackets, kind of similar to how we put the size of

194
00:14:44,920 --> 00:14:45,460
the array.

195
00:14:45,480 --> 00:14:51,190
Sometimes here, we didn't write just for this example because we had it explicitly initialized, but

196
00:14:51,340 --> 00:14:53,920
previously we put a size in between the square brackets, right?

197
00:14:54,340 --> 00:15:00,940
So we're going to use the variable numbers and we're going to put the position we're interested in inside

198
00:15:00,940 --> 00:15:07,660
of the square brackets and that all of this together well, I'm circling right here will give us access

199
00:15:07,660 --> 00:15:09,780
to this value right here.

200
00:15:09,790 --> 00:15:15,970
So if I was to do this in code, it would give me back one right here, right?

201
00:15:17,910 --> 00:15:24,630
Same thing right here, let's say I say numbs and square bracket, too close square bracket that is

202
00:15:24,630 --> 00:15:30,750
going to refer to three, so it gives me a way to access this number three in here because it's at position

203
00:15:30,750 --> 00:15:34,050
two, and I referred to the position correctly with this index.

204
00:15:35,630 --> 00:15:41,630
So like I just said, use the name of the array, followed by the square brackets and inside the square

205
00:15:41,630 --> 00:15:47,570
brackets, you put the position of the element like this, the name of the array, so variable name

206
00:15:47,570 --> 00:15:51,620
and then the position inside of these square brackets and of course, finished with the semicolon there.

207
00:15:53,090 --> 00:15:54,860
So this is called subscript.

208
00:15:55,490 --> 00:16:00,610
When you use the square brackets to access something with a position that is called subscript.

209
00:16:03,480 --> 00:16:09,170
So an important thing like just to reiterate, always starts at zero with the positioning, right?

210
00:16:09,210 --> 00:16:10,560
Zero one two three.

211
00:16:11,070 --> 00:16:18,840
The positioning of these four numbers in here, the last element in the array is always found at subscript

212
00:16:19,290 --> 00:16:20,550
size minus one.

213
00:16:20,580 --> 00:16:21,810
Well, let's take a look at that.

214
00:16:21,990 --> 00:16:23,970
What is the size of this array right here?

215
00:16:24,810 --> 00:16:30,600
Well, I'm not going to count starting at zero for the size, I'm only counting zero for the position

216
00:16:30,600 --> 00:16:31,200
labeling.

217
00:16:32,010 --> 00:16:34,320
The straight up fact is that there's four things in here, right?

218
00:16:34,320 --> 00:16:35,680
One two three four.

219
00:16:35,700 --> 00:16:37,080
So four things in here.

220
00:16:37,710 --> 00:16:40,920
So we're talking about what is the last element in the array?

221
00:16:40,950 --> 00:16:44,430
Well, it's three, which is size minus one, right?

222
00:16:44,430 --> 00:16:47,160
Because there's four things in the array four minus one is three.

223
00:16:47,880 --> 00:16:52,110
The reason that it will always be size minus one to access.

224
00:16:52,110 --> 00:16:58,620
The last thing is because we start counting the positions at the zero, which is like an offset of one,

225
00:16:58,620 --> 00:16:58,920
right?

226
00:16:59,490 --> 00:17:00,750
We started at one.

227
00:17:01,140 --> 00:17:04,460
The last thing in the array would just be at the size of the array, right?

228
00:17:04,470 --> 00:17:05,130
It would be a fourth.

229
00:17:05,130 --> 00:17:06,210
We have four items.

230
00:17:06,450 --> 00:17:09,150
The last thing is going to be the fourth position.

231
00:17:09,870 --> 00:17:13,660
But in this case, since we started zero, you notice it's all shifted by one.

232
00:17:13,680 --> 00:17:17,010
That's why the last thing is going to be always outsized minus one.

233
00:17:19,300 --> 00:17:25,690
So the balance of the array will always be zero and size minus one, respectively, for the front of

234
00:17:25,690 --> 00:17:27,170
the array and the back of the array.

235
00:17:27,190 --> 00:17:30,430
The very first position and the very last position for all arrays.

236
00:17:31,990 --> 00:17:37,480
Anything less than zero or greater than size minus one will be considered out of bounds, and this will

237
00:17:37,480 --> 00:17:44,860
often lead to an error because C++ will not want you to access stuff outside of balance because if this

238
00:17:44,860 --> 00:17:50,260
is like a chunk of memory, if you go outside of the bounds, that's kind of like some no man's land

239
00:17:50,260 --> 00:17:51,300
who knows what's there.

240
00:17:51,310 --> 00:17:56,680
You don't want to be accessing those parts of the computer's memory if it hasn't been explicitly defined

241
00:17:56,680 --> 00:17:59,200
by the C++ program with the correct syntax.

242
00:18:01,170 --> 00:18:04,770
So name array zero is red.

243
00:18:04,860 --> 00:18:08,670
Name array, sub zero because we call it subscript.

244
00:18:08,820 --> 00:18:09,080
Right.

245
00:18:09,090 --> 00:18:16,350
So if you want to refer to it short, you want to say in syntax it name or a left bracket, zero or

246
00:18:16,680 --> 00:18:23,310
right bracket, you would call that name or a subzero subsub, of course, being short for it subscript

247
00:18:23,310 --> 00:18:25,620
and the zero being the position.

248
00:18:28,880 --> 00:18:35,330
So some more subscript in here, we have an array of floats that as implicitly initialized with this

249
00:18:35,330 --> 00:18:35,900
list.

250
00:18:37,090 --> 00:18:42,970
So if you want to access something and print it out with CE out, we could do something like this,

251
00:18:42,970 --> 00:18:44,680
so this would be the complete syntax.

252
00:18:45,310 --> 00:18:50,710
We have the sea out and the operator, and then we put the name of the array, which is float array.

253
00:18:51,640 --> 00:18:56,670
We put the subscript square brackets and inside of here we have zero.

254
00:18:56,680 --> 00:18:59,560
So this would be float arrays, subzero.

255
00:19:00,010 --> 00:19:02,880
What is at the zeroth position?

256
00:19:02,890 --> 00:19:05,320
It's seven point one that is the first thing.

257
00:19:06,420 --> 00:19:11,700
We have an in line, so this would print seven point one and then go to a new line.

258
00:19:13,100 --> 00:19:19,370
We can also not only access it and print it out, but I told you it just refers to that position, right?

259
00:19:19,370 --> 00:19:23,030
Floater a subzero just refers to this position here.

260
00:19:23,030 --> 00:19:28,280
So rather than printing it out, we can actually change what's at that position.

261
00:19:28,280 --> 00:19:32,960
So I could also do something like this float array subzero.

262
00:19:33,020 --> 00:19:35,090
I'm referring to it in this manner now.

263
00:19:35,090 --> 00:19:38,880
Floater eight seven zero equals one point zero two.

264
00:19:38,900 --> 00:19:41,600
Well, we were referring to this right here, right?

265
00:19:41,630 --> 00:19:43,640
We use 0th item in their fluttery.

266
00:19:43,670 --> 00:19:45,410
Some zero is seven point one.

267
00:19:45,770 --> 00:19:51,140
Once I say equals one point zero two, what does the array look like now?

268
00:19:51,170 --> 00:19:56,750
Well, this is no longer seven point one is now one point zero two and haven't changed the other items.

269
00:19:56,750 --> 00:19:59,390
I've just changed what was at position zero.

270
00:20:03,090 --> 00:20:09,360
Another cool thing is being able to find out the size of the array when you do not know the size of

271
00:20:09,360 --> 00:20:09,750
the array.

272
00:20:09,840 --> 00:20:15,600
So this is only really used when you've declared and fully initialize the array using the implicit array,

273
00:20:15,600 --> 00:20:22,530
sizing something like this where you provide this list or if you want to, of course, just have the

274
00:20:22,530 --> 00:20:27,890
size of very available in a variable, but you may not necessarily know it.

275
00:20:27,900 --> 00:20:32,490
Maybe it's just not known to you at the time which you're writing that code.

276
00:20:34,160 --> 00:20:37,790
So you want a story that computed size and available for later use?

277
00:20:39,110 --> 00:20:42,110
You have to use a special thing called size of.

278
00:20:43,260 --> 00:20:47,160
So remember that the array size needs to be a constant.

279
00:20:48,390 --> 00:20:51,270
So that's why we're putting in constant array size.

280
00:20:51,630 --> 00:20:51,960
Right?

281
00:20:53,000 --> 00:20:59,000
And rather than saying constant array size equals seven or something like that, we can get this size

282
00:20:59,000 --> 00:20:59,600
of an array.

283
00:20:59,610 --> 00:21:02,580
So let's just say we have this array right here, right?

284
00:21:02,690 --> 00:21:04,860
We didn't really say what the size was.

285
00:21:04,880 --> 00:21:09,440
It was just empty brackets, but we put the amount of things in here, right?

286
00:21:09,660 --> 00:21:11,070
And we can see there's four.

287
00:21:11,090 --> 00:21:12,220
And we said, there's four.

288
00:21:12,230 --> 00:21:13,430
So we know that there's four.

289
00:21:13,430 --> 00:21:20,390
But if we want to save the size and a variable, so let's say we wanted to access something at the size

290
00:21:20,390 --> 00:21:22,100
minus one, which would be the last, right?

291
00:21:22,460 --> 00:21:31,130
If we want to make a variable that is the size so we can somehow do float array sub size minus one,

292
00:21:31,130 --> 00:21:32,160
so size minus one.

293
00:21:32,160 --> 00:21:34,910
And here we need to make a variable size first, right?

294
00:21:35,300 --> 00:21:38,650
And we don't know the sizes and to find here, we haven't already made a variable.

295
00:21:38,660 --> 00:21:39,800
So how do we do that?

296
00:21:40,100 --> 00:21:46,880
We have to use this special size of thing, which is actually a function, and we're going to get into

297
00:21:46,880 --> 00:21:48,410
functions later on.

298
00:21:50,000 --> 00:21:52,010
So don't concern yourself too much with that.

299
00:21:52,010 --> 00:21:56,000
Just kind of memorize the syntax of this and what we need to do here.

300
00:21:56,030 --> 00:22:00,250
So it says size of one word has a little parentheses.

301
00:22:01,550 --> 00:22:06,950
And inside here, we essentially need to divide.

302
00:22:08,480 --> 00:22:11,030
We need to take the array name, right?

303
00:22:11,630 --> 00:22:13,970
So this is the actual array, the variable.

304
00:22:15,510 --> 00:22:23,010
We didn't divide the size of the array by the size of one of the elements, so this divides the number

305
00:22:23,010 --> 00:22:30,720
of bytes allocated by the entire array with or by the number of bytes allocated for only one element

306
00:22:30,720 --> 00:22:31,440
of the array.

307
00:22:32,640 --> 00:22:33,000
Right.

308
00:22:34,160 --> 00:22:41,690
So it's kind of like, let's use some other little analogy, let's just say you have like a stack of

309
00:22:41,690 --> 00:22:43,300
cookies, right?

310
00:22:45,030 --> 00:22:50,190
And you want to know, you know, how tall is the stack of cookies?

311
00:22:51,200 --> 00:22:51,560
All right.

312
00:22:53,270 --> 00:22:58,370
But you don't you don't really know like you don't know how tall the stack of cookies is.

313
00:22:59,960 --> 00:23:01,380
And you don't really know.

314
00:23:02,010 --> 00:23:07,130
You know, maybe you know how to find out how big one cookie is, right?

315
00:23:07,880 --> 00:23:14,780
So if you want to if you want to just know, let's say, let's say you have a stack of cookies, but

316
00:23:14,780 --> 00:23:18,860
you just you don't really know how many cookies are there, right?

317
00:23:19,580 --> 00:23:21,740
Like how many cookies are on the stack of cookies.

318
00:23:23,140 --> 00:23:29,890
But someone says, OK, well, I can give you the size of the stack of cookies and height, right?

319
00:23:30,100 --> 00:23:37,090
So I can say, you know, the height of the cookies is blah blah blah and whatever you're going to say,

320
00:23:37,090 --> 00:23:38,410
let's say bites, right?

321
00:23:39,220 --> 00:23:40,900
Let's just say we're measuring it in bytes.

322
00:23:40,900 --> 00:23:41,940
I know that doesn't make sense.

323
00:23:41,950 --> 00:23:44,890
You probably measure it in like inches or centimeters or something like that.

324
00:23:45,280 --> 00:23:51,910
Let's just say the height of the cookies or like, let's say you had the cookies stacked like horizontally

325
00:23:51,910 --> 00:23:53,940
on a table and they were somehow standing up.

326
00:23:53,950 --> 00:23:56,950
Maybe you have them in a container and they're just going horizontally.

327
00:23:56,980 --> 00:24:02,230
Either way, if you want to think of it that way, if it's easier like an array you say, like, well,

328
00:24:02,230 --> 00:24:08,200
the total stack of cookies is like this many bytes, so you'd want to you could find that out with this

329
00:24:08,200 --> 00:24:08,470
right?

330
00:24:09,780 --> 00:24:11,880
How long is the stack of cookies?

331
00:24:11,970 --> 00:24:15,650
Well, size of the stack of cookies, right?

332
00:24:15,660 --> 00:24:18,030
Let's just call it stack of cookies in here.

333
00:24:20,120 --> 00:24:27,770
If you wanted to figure out how many cookies there were, you would basically have to divide the length

334
00:24:27,770 --> 00:24:30,030
of the stack of cookies, right?

335
00:24:30,050 --> 00:24:36,830
So we have like the length and bytes of the stack of cookies by how long one cookie is right or the

336
00:24:36,830 --> 00:24:40,790
size of one cookie, because that would give you the amount of cookies.

337
00:24:41,860 --> 00:24:43,260
So that's why we're doing that, right?

338
00:24:43,510 --> 00:24:50,080
This is like, you know, the size of the stack of cookies divided by the size of one cookie and this

339
00:24:50,080 --> 00:24:51,910
all together is going to give us.

340
00:24:53,210 --> 00:24:56,330
How many cookies are in that stack, right?

341
00:24:58,230 --> 00:25:03,120
So that's why we're doing this, the size of the array divided by the size of.

342
00:25:04,050 --> 00:25:06,060
One item in the array.

343
00:25:06,090 --> 00:25:06,510
All right.

344
00:25:07,260 --> 00:25:12,480
So you can imagine a stack of something in your head, you need to know the size of one of the items

345
00:25:12,960 --> 00:25:15,960
and you need to know the size of all the items stacked together.

346
00:25:16,200 --> 00:25:22,020
And that will give you that will give you access by doing this formula to know how many items are in

347
00:25:22,020 --> 00:25:24,000
there, how many items are in that stack.

348
00:25:24,630 --> 00:25:27,450
So here is how you access one item, right?

349
00:25:28,140 --> 00:25:30,770
If they're all the same type, right?

350
00:25:31,080 --> 00:25:33,180
All the cookies are the same size.

351
00:25:33,570 --> 00:25:36,600
It doesn't really matter which one you access, right?

352
00:25:37,350 --> 00:25:39,060
Doesn't matter which one you refer to.

353
00:25:39,090 --> 00:25:43,860
You could be like Cookie zero, cookie three cookie rule like one, whatever.

354
00:25:44,280 --> 00:25:45,740
They're all the same size.

355
00:25:45,750 --> 00:25:48,420
You just need to know the size of one of them.

356
00:25:48,990 --> 00:25:50,700
So that's why we're doing this here.

357
00:25:51,000 --> 00:25:53,460
Array name Sub-Zero.

358
00:25:53,790 --> 00:25:56,430
We could do a rename serve one, but like, why do that?

359
00:25:56,460 --> 00:26:02,370
Why don't we do the very first item in the array, which is at positions zero, right?

360
00:26:03,120 --> 00:26:05,820
We don't really know how big the array is.

361
00:26:06,300 --> 00:26:09,090
The array could only have one item in it.

362
00:26:09,510 --> 00:26:09,870
Right?

363
00:26:10,500 --> 00:26:18,000
If the array only has one item in it, then we don't want to do something at array name sub one.

364
00:26:19,050 --> 00:26:25,350
Because a Ray sub, someone would have to mean that there's two items in it, right, because we start

365
00:26:25,350 --> 00:26:26,470
counting at zero.

366
00:26:26,490 --> 00:26:29,230
The first position is always zero.

367
00:26:29,250 --> 00:26:34,140
So imagine you just have like a curly brace and then an item in another curly brace.

368
00:26:35,840 --> 00:26:40,520
You can't refer to one one is like outside of the curly braces, if there's only one item.

369
00:26:40,850 --> 00:26:44,390
The only subscript is zero, the only position is zero.

370
00:26:44,810 --> 00:26:51,860
That's why it's the safe way is to just do the name of the array sub zero once you know the size of

371
00:26:51,860 --> 00:26:53,630
that item at the very front.

372
00:26:54,650 --> 00:27:01,070
Then you can use the size of the whole array divided by that size of one item, and that will, of course,

373
00:27:01,070 --> 00:27:03,680
give you how many things are in the array.

374
00:27:03,710 --> 00:27:07,810
We're calling it array size, but it's really like how many things are in the array.

375
00:27:07,820 --> 00:27:09,260
You know, it's size seven.

376
00:27:09,860 --> 00:27:11,930
It has seven items in it, right?

377
00:27:14,550 --> 00:27:19,980
So kind of long winded explanation there, but I felt like it was necessary to really break it down

378
00:27:19,980 --> 00:27:24,630
because this might be a little too confusing, too confusing to just look at all of this at once and

379
00:27:24,630 --> 00:27:25,380
kind of absorb it.

380
00:27:27,060 --> 00:27:31,070
So if we want to print out everything in an array, we've kind of already done this right.

381
00:27:31,080 --> 00:27:35,370
We printed out something opposition position, whatever we can print out.

382
00:27:36,090 --> 00:27:41,760
You know, this will all print in a line, basically because we're just putting a semicolon at the end,

383
00:27:41,760 --> 00:27:43,830
but we say, see out array zero.

384
00:27:43,860 --> 00:27:44,820
What would that print?

385
00:27:45,120 --> 00:27:46,350
Will it print 10, right?

386
00:27:46,590 --> 00:27:48,420
Then we say, see out my array one.

387
00:27:48,420 --> 00:27:51,870
We haven't done a new line, so it would just we just have a space here.

388
00:27:52,780 --> 00:27:59,740
So it would be like 10 space, 20 space, 30 space, 40, right?

389
00:27:59,950 --> 00:28:06,310
Because they're zero one to three and we're printing out my race of zero, my weight race, a one mile

390
00:28:06,310 --> 00:28:08,200
race of to my race of three.

391
00:28:12,350 --> 00:28:17,870
So this is where I'm going to kind of leave off, I don't want to push it too much with the amount of

392
00:28:17,870 --> 00:28:23,750
information, this might be one of those videos where you might need to watch it through a second time

393
00:28:23,900 --> 00:28:27,320
if it's just too much to absorb and one long push.

394
00:28:28,250 --> 00:28:29,660
And that's totally fine.

395
00:28:30,620 --> 00:28:35,720
We have covered a lot, but these are very important and we're going to move forward with containers

396
00:28:36,410 --> 00:28:40,670
to be able to make more complex programs and do more interesting things, right?

397
00:28:40,700 --> 00:28:41,870
That's the point of all this.

398
00:28:42,910 --> 00:28:49,720
So with that, I will see you in the next lecture and we will start using these arrays.
