Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,180 --> 00:00:06,360
All right, so at this point, we know how to declare a standard variable, we know how to declare a
2
00:00:06,360 --> 00:00:11,930
one dimensional array, and also we've covered how we can declare a two dimensional array.
3
00:00:12,600 --> 00:00:16,980
And now what I want us to talk about is how to initialize them.
4
00:00:17,730 --> 00:00:19,530
Basically initializing.
5
00:00:19,530 --> 00:00:27,240
What it means is how can we declare and assign some content to a variable at the same time.
6
00:00:27,750 --> 00:00:35,050
So to initialize a standard variable, we could just declare it and assign a value right afterwards.
7
00:00:35,100 --> 00:00:40,720
So, for example, we've seen and we already know how it can be done Inam equals to five.
8
00:00:41,130 --> 00:00:51,000
So what we do here is we basically declare and also assign some initialize some initial value to this
9
00:00:51,000 --> 00:00:51,750
variable.
10
00:00:51,760 --> 00:00:59,000
And also we can do so for variables of different types, for variables of double types, for variables
11
00:00:59,010 --> 00:01:01,410
of character types and so on.
12
00:01:01,440 --> 00:01:09,150
Also, if we wanted to initialize one dimensional arrays, we if you remember correctly, we used the
13
00:01:09,150 --> 00:01:12,100
curly brackets right after the assignment.
14
00:01:12,630 --> 00:01:22,080
So basically when we specified integrates with five elements, then in the curly brackets, we specified
15
00:01:22,080 --> 00:01:25,650
all the values that these grades array will have.
16
00:01:26,260 --> 00:01:33,930
And it actually doesn't really matter if it's or if it will be of an integer type, double type and
17
00:01:33,930 --> 00:01:34,470
so on.
18
00:01:35,310 --> 00:01:41,760
And basically, finally, to initialize two-dimensional arrays, we will also use some curly brackets.
19
00:01:41,820 --> 00:01:49,280
OK, very similar to how we've done it with one dimensional arrays, but in kind of another way.
20
00:01:49,710 --> 00:01:56,580
And that's because you see, guys, the two dimensional arrays, the whole process of initialization
21
00:01:56,880 --> 00:02:01,130
is actually kind of tricky and can be done in more than just one way.
22
00:02:01,620 --> 00:02:09,060
And for the sake of convenience, I would like to kind of categorize these ways as following.
23
00:02:09,540 --> 00:02:14,200
So let's talk about the first way, which is the standard way.
24
00:02:14,550 --> 00:02:20,610
So the first way is actually the most standard way to initialize a two dimensional array.
25
00:02:20,640 --> 00:02:27,600
It's probably what you're going to see most of the time in most of the examples that you're going to
26
00:02:27,600 --> 00:02:29,880
encounter in your programming career.
27
00:02:30,480 --> 00:02:38,460
So it's somewhat similar to the one dimensional array initialization with this usage of the curly brackets,
28
00:02:38,970 --> 00:02:43,160
just that now we are using more than one curly bracket.
29
00:02:43,170 --> 00:02:49,890
We initialize the values for each row in each pair of curly brackets.
30
00:02:49,920 --> 00:02:57,570
OK, so I think instead of just the formal definition that I've written here on this side, I think
31
00:02:57,570 --> 00:03:02,300
it will make more sense if we if I will show you this little nice example.
32
00:03:02,310 --> 00:03:10,370
So we create a two dimensional array with two rows and three columns and the external curly brackets
33
00:03:10,380 --> 00:03:11,290
like you see here.
34
00:03:11,310 --> 00:03:13,070
Let's take these laser, OK?
35
00:03:13,170 --> 00:03:20,820
And you can see here that we have both the out curly brackets and we also have some inside curly brackets
36
00:03:20,820 --> 00:03:25,710
and these external OK, these external curly brackets.
37
00:03:25,710 --> 00:03:32,280
What they actually do is that they describe the assignment operation to this matrix.
38
00:03:32,640 --> 00:03:36,780
OK, so basically we have the right side and we have the left side.
39
00:03:36,790 --> 00:03:45,390
So all of that goes right into feeling these two dimensional array that we've created and each internal
40
00:03:45,390 --> 00:03:46,370
curly bracket.
41
00:03:46,380 --> 00:03:48,330
OK, so each pair here, OK.
42
00:03:48,560 --> 00:03:54,820
Basically what it does, it describes the values for each row in this matrix.
43
00:03:55,500 --> 00:04:02,320
So for the first row, we are going to have like these two, three values.
44
00:04:02,340 --> 00:04:07,050
OK, so you have two rows, OK, two rows and three columns.
45
00:04:07,320 --> 00:04:15,030
And of these first let's call it triple Bearak, so it goes and feels these first row.
46
00:04:15,030 --> 00:04:23,520
So one, two, three goes and feels these first row and then you have additional internal curly brackets.
47
00:04:23,730 --> 00:04:28,650
And what they do is that they feel the second row in this matrix.
48
00:04:28,770 --> 00:04:33,930
So very standard way to initialize previously with one dimensional arrays.
49
00:04:33,930 --> 00:04:42,590
We just use like one one pair of those and we specified all the values for the one dimensional array.
50
00:04:42,600 --> 00:04:48,240
So here are think about it like we have a couple of one dimensional arrays, like think about it.
51
00:04:48,450 --> 00:04:51,410
Every row is a one dimensional array, OK?
52
00:04:51,420 --> 00:04:57,930
It's not exactly the way it is behind the scenes, but maybe it will help you to understand this a little
53
00:04:57,930 --> 00:04:59,430
bit easier.
54
00:04:59,940 --> 00:05:07,140
And now let's take a look at another example where we are using floating point types, so basically
55
00:05:07,140 --> 00:05:14,940
what we have here is a new two dimensional array with three rows and two columns, and each of the internal
56
00:05:14,940 --> 00:05:22,170
curly brackets is going to be of size to mean just with two elements, because we have three rows and
57
00:05:22,170 --> 00:05:27,990
two columns in two columns are just enough to fill up each and every row.
58
00:05:28,110 --> 00:05:35,670
So kind of to summarize what we've done so far, basically in the first and third way, we can say that
59
00:05:36,120 --> 00:05:44,490
this way simply refers to when the internal curly brackets, like you can see here and here, have the
60
00:05:44,490 --> 00:05:49,580
exact amount of values to complete just one row.
61
00:05:49,590 --> 00:05:55,740
So meaning you're looking at these curly brackets and you can see here are two, two and two values
62
00:05:55,740 --> 00:05:58,530
at each internal curly bracket.
63
00:05:58,950 --> 00:06:03,330
And you can see also that that's the exact amount of values.
64
00:06:05,310 --> 00:06:07,230
That's the exact amount of columns.
65
00:06:07,260 --> 00:06:08,700
OK, so here are two.
66
00:06:08,700 --> 00:06:11,210
Here you have three values, three columns.
67
00:06:11,400 --> 00:06:16,710
So that's basically the standard way to initialize two dimensional array.
68
00:06:17,760 --> 00:06:19,380
So that's pretty simple.
69
00:06:19,380 --> 00:06:21,180
Nothing complicated, right, guys?
70
00:06:21,430 --> 00:06:24,360
Basically, you can use it in this theory out there.
71
00:06:24,390 --> 00:06:26,990
It works also on your side.
72
00:06:27,540 --> 00:06:28,040
Great.
73
00:06:28,050 --> 00:06:32,690
And now let's proceed to our second option, OK?
74
00:06:33,270 --> 00:06:40,150
And this option, I call it like incomplete values in the internal curly brackets.
75
00:06:40,260 --> 00:06:48,180
So in the previous standard way, we defined the exact amount of values for every row in each internal
76
00:06:48,180 --> 00:06:49,260
curly bracket.
77
00:06:49,800 --> 00:06:57,510
Now, I want to talk with you about another type of initialization where we have incomplete internal
78
00:06:57,510 --> 00:07:05,400
curly brackets, meaning suppose that you declare the two dimensional array with two rows and let's
79
00:07:05,400 --> 00:07:07,550
say, three columns for each row.
80
00:07:08,010 --> 00:07:15,120
And up until now, you've learned that you have to specify the exact amount of values as there are in
81
00:07:15,120 --> 00:07:18,330
each row for these two dimensional array.
82
00:07:18,360 --> 00:07:18,660
Right.
83
00:07:18,660 --> 00:07:21,350
That's what we've seen in a standard approach.
84
00:07:21,840 --> 00:07:30,180
But actually, there may be times when you don't want to or you don't have the option to provide all
85
00:07:30,180 --> 00:07:33,150
of these values for some two dimensional array.
86
00:07:33,180 --> 00:07:35,070
OK, this also may happen.
87
00:07:35,700 --> 00:07:43,950
And in this case, you can specify just the number of values that you can or need for each row.
88
00:07:44,190 --> 00:07:46,790
So let's take a look at this example.
89
00:07:47,130 --> 00:07:52,980
So we're creating a matrix, a two dimensional array with two rows.
90
00:07:53,050 --> 00:07:55,770
OK, here it is, two rows and three columns.
91
00:07:56,220 --> 00:08:04,260
And basically what we can see here is just that in each of these curly brackets, internal curly brackets,
92
00:08:04,260 --> 00:08:11,400
we don't specify the exact number of values as there are columns here.
93
00:08:11,400 --> 00:08:18,270
Right here are three columns, but we specify, first of all, just two values and then just one value.
94
00:08:18,360 --> 00:08:26,230
So in this case, we will just pad OK with a zero all the missing values in each row.
95
00:08:26,580 --> 00:08:32,520
So for the first row, we will add like five and six, OK, because we have here five and six.
96
00:08:32,550 --> 00:08:41,310
And for the second row we will add just these seven and everything that comes after the last value that
97
00:08:41,310 --> 00:08:49,140
was specified here in each of the internal curly brackets, we will simply pad with zeros.
98
00:08:49,530 --> 00:08:56,520
So for the second row, we basically for the first row we will add just one zero.
99
00:08:56,520 --> 00:09:04,200
And for the second row we will add these two zeros at the end just to like to feel these two dimensional
100
00:09:04,830 --> 00:09:12,360
array that it will have basically that it will not have any one initialized values.
101
00:09:12,610 --> 00:09:20,160
So the values that we know that should be there and also the values that we don't know and on or maybe
102
00:09:20,160 --> 00:09:27,450
we are not sure yet what they should be, then let's just add them and set them to be zero.
103
00:09:27,690 --> 00:09:31,830
Another example would be like to use these metrics.
104
00:09:31,860 --> 00:09:40,200
OK, we have four rows, three columns, and you can see here that in the first row we do not feel to
105
00:09:40,440 --> 00:09:42,020
deal with all the values.
106
00:09:42,030 --> 00:09:45,720
So we have one, two and zero and then we have four or five.
107
00:09:45,720 --> 00:09:46,920
Eight, which is OK.
108
00:09:46,920 --> 00:09:48,810
We don't have to feel well.
109
00:09:48,810 --> 00:09:52,680
Nothing with away the zeros you have also ten.
110
00:09:52,800 --> 00:09:56,850
OK, ten and two zeros, OK, because that's just one column.
111
00:09:57,150 --> 00:09:59,550
And also the last row is also.
112
00:09:59,630 --> 00:10:02,250
We will be filled with zeros.
113
00:10:02,900 --> 00:10:12,440
So once again, guys, don't take anything that I teach here is kind of like kind of you get the information
114
00:10:12,440 --> 00:10:13,900
and you say, oh, OK.
115
00:10:13,910 --> 00:10:17,330
So he said that this is exactly how it works.
116
00:10:17,330 --> 00:10:18,770
And I'm sure about it.
117
00:10:18,980 --> 00:10:20,780
I will go to my exam.
118
00:10:20,780 --> 00:10:28,100
I will go to my interview, whatever it is, and I will just like tell them that that's how initialization
119
00:10:28,100 --> 00:10:29,730
of two dimensional arrays work.
120
00:10:30,150 --> 00:10:31,520
No, that's not the case.
121
00:10:31,700 --> 00:10:32,070
Please.
122
00:10:32,300 --> 00:10:39,590
Everything that I use here in this video and in the previous videos and in the future videos and everything
123
00:10:39,590 --> 00:10:43,790
that you hear also on lectures, just make sure that it works.
124
00:10:44,030 --> 00:10:46,450
Go to your idea, OK?
125
00:10:46,490 --> 00:10:54,200
And write these lines of code, test it out, make sure that it's exactly as you think and it's exactly
126
00:10:54,200 --> 00:10:55,940
as your teacher says.
127
00:10:55,940 --> 00:11:02,810
And only once you do so, you basically will confirm that you understand everything that is being told.
128
00:11:02,880 --> 00:11:07,670
OK, so don't don't take anything like I don't know how to say it is.
129
00:11:07,670 --> 00:11:12,830
Granted, the like is obvious and like to rely on it for 100 percent.
130
00:11:12,920 --> 00:11:17,600
No, guys go and check it out for yourself and be sure of what you're doing.
131
00:11:17,630 --> 00:11:21,020
And also that will be nice practice for you.
132
00:11:21,740 --> 00:11:27,150
So let's move on to our last example here that I just wanted to mention you.
133
00:11:27,350 --> 00:11:31,940
So here in the first row, we specify an empty, curly bracket.
134
00:11:32,000 --> 00:11:36,340
OK, so it will be filled with zeros, OK, because we don't have any column.
135
00:11:36,740 --> 00:11:44,630
Then we have these five point two and one point zero and lastly, three point three and zero at the
136
00:11:44,630 --> 00:11:47,280
end to fill these with with zeros.
137
00:11:47,540 --> 00:11:55,400
So the question is that I am asking you is try to check it out and print the values also of these two
138
00:11:55,400 --> 00:12:01,850
dimensional array and make sure that if we didn't specify here the empty curly brackets like we've done
139
00:12:01,850 --> 00:12:04,490
here, will this still look like this?
140
00:12:04,490 --> 00:12:08,630
Or maybe we should just specified here empty curly brackets.
141
00:12:08,780 --> 00:12:12,350
And that's why I'm telling you to test everything out.
142
00:12:12,740 --> 00:12:16,720
So maybe and maybe not, but I'm leaving of these to you guys.
143
00:12:16,730 --> 00:12:24,590
OK, and lastly, let's talk about the third way to initialize arrays and of these ways called the excessive
144
00:12:24,590 --> 00:12:27,730
values in the internal curly brackets.
145
00:12:28,280 --> 00:12:33,280
So we talked about two situations for two dimensional array initialization.
146
00:12:33,320 --> 00:12:40,190
The first one is where we have the exact amount of values for each row in the internal curly bracket.
147
00:12:40,190 --> 00:12:48,530
And the second one is about the time where there are less values for each row than it should be.
148
00:12:48,570 --> 00:12:49,150
All right.
149
00:12:49,700 --> 00:12:52,760
And we've also seen a couple of examples for each of them.
150
00:12:53,790 --> 00:13:01,820
And now what we want to talk about is a situation where there are more values for each row in the internal
151
00:13:01,820 --> 00:13:02,920
curly brackets.
152
00:13:03,290 --> 00:13:09,680
So basically, each of these situations, we are not going to cover where exactly they may happen.
153
00:13:09,680 --> 00:13:16,130
But there are times when you probably will use one of them at least.
154
00:13:16,160 --> 00:13:25,070
OK, but you are going to also to encounter with different types of writing and different types of programmers
155
00:13:25,070 --> 00:13:26,800
that one prefer this way.
156
00:13:26,810 --> 00:13:28,600
The other one prefer that way.
157
00:13:28,730 --> 00:13:33,440
And it's important that you will like you whenever you are going to look at it.
158
00:13:33,650 --> 00:13:36,380
You will not go like really scared until.
159
00:13:36,380 --> 00:13:40,820
Oh, wait, but you specified here less or more values than it should be.
160
00:13:41,000 --> 00:13:46,930
It only has three zero three columns, but you specified five core values for this row.
161
00:13:46,940 --> 00:13:47,870
What is going on.
162
00:13:48,140 --> 00:13:58,460
OK, so my goal is like two for you to be relaxed and give you all at least I'm trying it most of the
163
00:13:58,460 --> 00:14:04,480
options that you are going to encounter during your career and to make life easier for you.
164
00:14:04,670 --> 00:14:15,200
So let's say that we have this example, so intimate, two and three, OK, two rows, three columns.
165
00:14:15,650 --> 00:14:22,610
And we can see that there are more than just three values for the first row.
166
00:14:22,610 --> 00:14:23,030
Right.
167
00:14:23,040 --> 00:14:26,480
So we can see here five to one, six and five.
168
00:14:27,080 --> 00:14:32,540
So the question is, that's what will happen behind the scenes.
169
00:14:32,540 --> 00:14:40,370
OK, so should we feel like, you know, like feel the first row, feel the second row, what does it
170
00:14:40,370 --> 00:14:41,260
refer to?
171
00:14:41,870 --> 00:14:47,270
So actually, if you come to think about it, that's very easy to interpret.
172
00:14:47,270 --> 00:14:50,480
We're simply going to take all of these values here.
173
00:14:50,480 --> 00:14:58,610
We have five of them and simply feel them, one after the other to our two dimensional array from left
174
00:14:58,610 --> 00:14:59,240
to right.
175
00:14:59,820 --> 00:15:07,590
OK, so we are simply going to feel the first three values to here, OK, to the first row, and once
176
00:15:07,590 --> 00:15:12,900
we are done with the first row and we know that we are not finished yet, we are simply going to slide
177
00:15:12,900 --> 00:15:19,640
over to the next row and start feeling the next row with the values that are remaining.
178
00:15:19,650 --> 00:15:25,980
So with the values of five, two and one, go to the first row in the values six, five, go to the
179
00:15:25,980 --> 00:15:26,900
second row.
180
00:15:27,150 --> 00:15:33,360
And since we don't have anything else to do, we will feel it with a zero at the end.
181
00:15:33,510 --> 00:15:40,440
OK, guys, so I think we've covered pretty nice and pretty are awesome options.
182
00:15:40,590 --> 00:15:47,550
Also, what I can see here in this example, and that's also why it's so important for you to give it
183
00:15:47,550 --> 00:15:53,700
a try to see if you're getting any warnings, any errors, because nothing is perfect and sometimes
184
00:15:53,700 --> 00:15:57,840
mistakes happen also to the student and also to the teacher.
185
00:15:58,350 --> 00:16:00,180
And everybody does mistakes.
186
00:16:00,450 --> 00:16:08,970
And my suggestion to you is like to be very, very aware of what you hear and of what you read into.
187
00:16:09,270 --> 00:16:16,560
One of the questions that probably are you are going to ask me is whether you should or should not have
188
00:16:16,740 --> 00:16:22,020
added additional curly bracket here, OK, internal curly bracket.
189
00:16:22,170 --> 00:16:25,110
And only then this option would have worked.
190
00:16:25,440 --> 00:16:28,770
And if not, OK, why is that working?
191
00:16:28,770 --> 00:16:32,700
And maybe you are getting some error or some warning.
192
00:16:32,700 --> 00:16:39,780
And basically what will be the difference, if you will use this way or if you have just added additional
193
00:16:39,780 --> 00:16:40,850
curly bracket?
194
00:16:40,890 --> 00:16:42,240
So awesome, guys.
195
00:16:42,240 --> 00:16:49,590
I think that I've managed to like to give you this lesson of testing out also your teacher.
196
00:16:49,890 --> 00:16:55,050
And what I can say to you guys for this video is great job.
197
00:16:55,830 --> 00:16:59,580
We've covered pretty much good material in this video.
198
00:16:59,940 --> 00:17:02,850
So write down the notes that you have.
199
00:17:02,850 --> 00:17:09,360
Go take a break and then come back fresh for the next superimportant video.
200
00:17:09,360 --> 00:17:11,100
And until then, goodbye.
21001
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.