All language subtitles for 2. 2D Arrays - Initialization + 3 Tricks to Initialize

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

All right, so at this point, we know how to declare a standard variable, we know how to declare a

one dimensional array, and also we've covered how we can declare a two dimensional array.

And now what I want us to talk about is how to initialize them.

Basically initializing.

What it means is how can we declare and assign some content to a variable at the same time.

So to initialize a standard variable, we could just declare it and assign a value right afterwards.

So, for example, we've seen and we already know how it can be done Inam equals to five.

So what we do here is we basically declare and also assign some initialize some initial value to this

variable.

And also we can do so for variables of different types, for variables of double types, for variables

of character types and so on.

Also, if we wanted to initialize one dimensional arrays, we if you remember correctly, we used the

curly brackets right after the assignment.

So basically when we specified integrates with five elements, then in the curly brackets, we specified

all the values that these grades array will have.

And it actually doesn't really matter if it's or if it will be of an integer type, double type and

so on.

And basically, finally, to initialize two-dimensional arrays, we will also use some curly brackets.

OK, very similar to how we've done it with one dimensional arrays, but in kind of another way.

And that's because you see, guys, the two dimensional arrays, the whole process of initialization

is actually kind of tricky and can be done in more than just one way.

And for the sake of convenience, I would like to kind of categorize these ways as following.

So let's talk about the first way, which is the standard way.

So the first way is actually the most standard way to initialize a two dimensional array.

It's probably what you're going to see most of the time in most of the examples that you're going to

encounter in your programming career.

So it's somewhat similar to the one dimensional array initialization with this usage of the curly brackets,

just that now we are using more than one curly bracket.

We initialize the values for each row in each pair of curly brackets.

OK, so I think instead of just the formal definition that I've written here on this side, I think

it will make more sense if we if I will show you this little nice example.

So we create a two dimensional array with two rows and three columns and the external curly brackets

like you see here.

Let's take these laser, OK?

And you can see here that we have both the out curly brackets and we also have some inside curly brackets

and these external OK, these external curly brackets.

What they actually do is that they describe the assignment operation to this matrix.

OK, so basically we have the right side and we have the left side.

So all of that goes right into feeling these two dimensional array that we've created and each internal

curly bracket.

OK, so each pair here, OK.

Basically what it does, it describes the values for each row in this matrix.

So for the first row, we are going to have like these two, three values.

OK, so you have two rows, OK, two rows and three columns.

And of these first let's call it triple Bearak, so it goes and feels these first row.

So one, two, three goes and feels these first row and then you have additional internal curly brackets.

And what they do is that they feel the second row in this matrix.

So very standard way to initialize previously with one dimensional arrays.

We just use like one one pair of those and we specified all the values for the one dimensional array.

So here are think about it like we have a couple of one dimensional arrays, like think about it.

Every row is a one dimensional array, OK?

It's not exactly the way it is behind the scenes, but maybe it will help you to understand this a little

bit easier.

And now let's take a look at another example where we are using floating point types, so basically

what we have here is a new two dimensional array with three rows and two columns, and each of the internal

curly brackets is going to be of size to mean just with two elements, because we have three rows and

two columns in two columns are just enough to fill up each and every row.

So kind of to summarize what we've done so far, basically in the first and third way, we can say that

this way simply refers to when the internal curly brackets, like you can see here and here, have the

exact amount of values to complete just one row.

So meaning you're looking at these curly brackets and you can see here are two, two and two values

at each internal curly bracket.

And you can see also that that's the exact amount of values.

That's the exact amount of columns.

OK, so here are two.

Here you have three values, three columns.

So that's basically the standard way to initialize two dimensional array.

So that's pretty simple.

Nothing complicated, right, guys?

Basically, you can use it in this theory out there.

It works also on your side.

Great.

And now let's proceed to our second option, OK?

And this option, I call it like incomplete values in the internal curly brackets.

So in the previous standard way, we defined the exact amount of values for every row in each internal

curly bracket.

Now, I want to talk with you about another type of initialization where we have incomplete internal

curly brackets, meaning suppose that you declare the two dimensional array with two rows and let's

say, three columns for each row.

And up until now, you've learned that you have to specify the exact amount of values as there are in

each row for these two dimensional array.

Right.

That's what we've seen in a standard approach.

But actually, there may be times when you don't want to or you don't have the option to provide all

of these values for some two dimensional array.

OK, this also may happen.

And in this case, you can specify just the number of values that you can or need for each row.

So let's take a look at this example.

So we're creating a matrix, a two dimensional array with two rows.

OK, here it is, two rows and three columns.

And basically what we can see here is just that in each of these curly brackets, internal curly brackets,

we don't specify the exact number of values as there are columns here.

Right here are three columns, but we specify, first of all, just two values and then just one value.

So in this case, we will just pad OK with a zero all the missing values in each row.

So for the first row, we will add like five and six, OK, because we have here five and six.

And for the second row we will add just these seven and everything that comes after the last value that

was specified here in each of the internal curly brackets, we will simply pad with zeros.

So for the second row, we basically for the first row we will add just one zero.

And for the second row we will add these two zeros at the end just to like to feel these two dimensional

array that it will have basically that it will not have any one initialized values.

So the values that we know that should be there and also the values that we don't know and on or maybe

we are not sure yet what they should be, then let's just add them and set them to be zero.

Another example would be like to use these metrics.

OK, we have four rows, three columns, and you can see here that in the first row we do not feel to

deal with all the values.

So we have one, two and zero and then we have four or five.

Eight, which is OK.

We don't have to feel well.

Nothing with away the zeros you have also ten.

OK, ten and two zeros, OK, because that's just one column.

And also the last row is also.

We will be filled with zeros.

So once again, guys, don't take anything that I teach here is kind of like kind of you get the information

and you say, oh, OK.

So he said that this is exactly how it works.

And I'm sure about it.

I will go to my exam.

I will go to my interview, whatever it is, and I will just like tell them that that's how initialization

of two dimensional arrays work.

No, that's not the case.

Please.

Everything that I use here in this video and in the previous videos and in the future videos and everything

that you hear also on lectures, just make sure that it works.

Go to your idea, OK?

And write these lines of code, test it out, make sure that it's exactly as you think and it's exactly

as your teacher says.

And only once you do so, you basically will confirm that you understand everything that is being told.

OK, so don't don't take anything like I don't know how to say it is.

Granted, the like is obvious and like to rely on it for 100 percent.

No, guys go and check it out for yourself and be sure of what you're doing.

And also that will be nice practice for you.

So let's move on to our last example here that I just wanted to mention you.

So here in the first row, we specify an empty, curly bracket.

OK, so it will be filled with zeros, OK, because we don't have any column.

Then we have these five point two and one point zero and lastly, three point three and zero at the

end to fill these with with zeros.

So the question is that I am asking you is try to check it out and print the values also of these two

dimensional array and make sure that if we didn't specify here the empty curly brackets like we've done

here, will this still look like this?

Or maybe we should just specified here empty curly brackets.

And that's why I'm telling you to test everything out.

So maybe and maybe not, but I'm leaving of these to you guys.

OK, and lastly, let's talk about the third way to initialize arrays and of these ways called the excessive

values in the internal curly brackets.

So we talked about two situations for two dimensional array initialization.

The first one is where we have the exact amount of values for each row in the internal curly bracket.

And the second one is about the time where there are less values for each row than it should be.

All right.

And we've also seen a couple of examples for each of them.

And now what we want to talk about is a situation where there are more values for each row in the internal

curly brackets.

So basically, each of these situations, we are not going to cover where exactly they may happen.

But there are times when you probably will use one of them at least.

OK, but you are going to also to encounter with different types of writing and different types of programmers

that one prefer this way.

The other one prefer that way.

And it's important that you will like you whenever you are going to look at it.

You will not go like really scared until.

Oh, wait, but you specified here less or more values than it should be.

It only has three zero three columns, but you specified five core values for this row.

What is going on.

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

options that you are going to encounter during your career and to make life easier for you.

So let's say that we have this example, so intimate, two and three, OK, two rows, three columns.

And we can see that there are more than just three values for the first row.

Right.

So we can see here five to one, six and five.

So the question is, that's what will happen behind the scenes.

OK, so should we feel like, you know, like feel the first row, feel the second row, what does it

refer to?

So actually, if you come to think about it, that's very easy to interpret.

We're simply going to take all of these values here.

We have five of them and simply feel them, one after the other to our two dimensional array from left

to right.

OK, so we are simply going to feel the first three values to here, OK, to the first row, and once

we are done with the first row and we know that we are not finished yet, we are simply going to slide

over to the next row and start feeling the next row with the values that are remaining.

So with the values of five, two and one, go to the first row in the values six, five, go to the

second row.

And since we don't have anything else to do, we will feel it with a zero at the end.

OK, guys, so I think we've covered pretty nice and pretty are awesome options.

Also, what I can see here in this example, and that's also why it's so important for you to give it

a try to see if you're getting any warnings, any errors, because nothing is perfect and sometimes

mistakes happen also to the student and also to the teacher.

And everybody does mistakes.

And my suggestion to you is like to be very, very aware of what you hear and of what you read into.

One of the questions that probably are you are going to ask me is whether you should or should not have

added additional curly bracket here, OK, internal curly bracket.

And only then this option would have worked.

And if not, OK, why is that working?

And maybe you are getting some error or some warning.

And basically what will be the difference, if you will use this way or if you have just added additional

curly bracket?

So awesome, guys.

I think that I've managed to like to give you this lesson of testing out also your teacher.

And what I can say to you guys for this video is great job.

We've covered pretty much good material in this video.

So write down the notes that you have.

Go take a break and then come back fresh for the next superimportant video.

And until then, goodbye.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.