All language subtitles for 8. Initializing a Struct in C

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.

What is going on, ladies and gentlemen, and welcome to another video in our amazing programming course.

And in this video, we are talking about how we can initialize a struct variable.

But before we jump into initializing, let us, first of all, take a look at this tronc definition

that we have.

So what we have here is basically struct point with two fields index ending, why OK, simply two fields

under the the roof of this new structure called point.

And we are using the type of definition to specify that instead of using struct point to create different

variables and work with data types of the new type struct point that we created.

Instead of using that, we can use simply point with a Capital B in this example.

OK, so point will be used to represent the type that we just created.

This new type, this new user, a defined structure called point.

All right.

So far, so good.

Awesome.

So at this moment, we still don't have any instances of the variable.

OK, any instances of the class point.

But what we are going to do now is to see maybe once again how to declare a point variable.

And basically how we can initialize in various ways.

OK.

So let us start.

So the first thing that we are going to take a look at is of Eastpointe P1, and all he does is just

to declare a point variable without any initialization.

So if we will simply draw it, it will look like this.

There will be p one and it's going to have two fields.

The first member is the X, the second one is Y, and it has some garbage values inside of it.

OK, so we simply created a bigger box called one with two members.

The second option is initializing a point variable when members are in order.

So we know that basically after just creating be one we could use, be one that X equals to some value

and b y be one that y equals do some other value.

Right.

There is no problem using the assigning operation, but sometimes we would like to make the initialization

right away.

OK.

Whenever we know the values themselves.

So instead of spreading it into a couple of rows, we can just write it down in one comment.

So in these command point B two and using the curly brackets, what we are getting is simply a variable

called B2.

It is of type, of course, point.

And then whenever we use the curly brackets, we simply start feeling more, at least hoping to feel

it, feeling the values for the data members of the struct.

So we remember the first one is the second one is Y.

So we simply put a value of five right here and seven right here.

And there you go.

You created your variable p with these two data members and these two values for each of them.

OK.

Another option for initialization is to use the designated initiate laser.

So how it looks like we create a new variable called P3, it needs of type point, and these variable

is going basically to be initialized with specifically or, let's say, explicitly specifying what members

should have, what values at the initialization step.

So we specify Dot X.

It means, like we've written, P 3.6 equals two, three and B three.

Dot Y equals two four.

So basically, P3 is going to look like this.

Three and four.

That's the AEC's, and that's the way.

OK.

Designated initial her specifying exactly to what members of the class we want to put exactly what value.

All right.

Awesome.

Now basically so far, we used all of the things in order, right, specifying first of all, the X

and then the Y.

But there may be times that we would like to specify, not in order.

So this way we can always more basically, hopefully always try to look, try using the designated initial

ICER and use the the values for each of the members in kind of out of order.

So that means that we will not necessarily specify as the first value in this initial ICER.

It doesn't necessarily have to be off a it doesn't necessarily have to be X.

OK.

We can specify that, first of all, we will specify the Y value and then the X OK.

And basically what we will get is simply be for with the values of two and 10.

OK.

So that's just a side note for you to be familiar with any questions.

Good.

So now we use the designated initialize.

The other members are initialized with zero.

So this basically refers to the fact that whenever we create a variable of some user, a defined type,

then we do not necessarily have to specify and to initialize all of its data members.

OK, maybe sometimes we don't know what value should some some member have.

So in this case, what we've done is basically we created P five and there are two fields.

The first one is X and it has the value of one.

And the second one is Y.

And we will say that it will not be with an empty valley where some garbage value.

We will say that by using these designated initialize, the other members that were not specified in

this initialize or step will be initialized with the value of zero.

So it will look like this.

OK, so what we've done here is basically we've seen a couple of options to initialize a variable offer

user defined type.

In this case, it's very simple because we have only two fields of type end, but it does not necessarily

have to be this way.

We know that the fields, the members of a certain user defined struct, they may be also of different

types.

We may have a double, we may have a float, we may have a lot of other things.

So we can also have a raise and so on and so forth.

He doesn't really matter.

Just make sure that whenever you initialize that the value you are trying to assign to a certain member

that it simply makes sense.

You would not want you would not want to take a string and to assign it to an integer.

OK.

And also probably not the other way around.

Good.

So the last thing that I want to do in this demonstration is basically, let's run.

The debugger and see for ourselves how we can simply take a look at these five variables that we've

created and what basically they hold so that this way you will know kind of more confident about the

things that I've just mentioned.

So if we take a look, we can see that here and the local section in the debugger, we are going to

see all of the variables.

OK, I'm simply using the debugging process, all of the variables that we've created because we are

now at the last row in the main function and we can see B1, B2, B3, PS4 and PS5.

And if we open them up, we will be able to see all the values inside of them.

But also we can see it right here, the value for the field and the value for a field of wine, so be

one is not initialized, right?

You remember P1, one is not initialized with anything.

So in this case, we simply have some garbage values inside of these X and Y data members.

B two has the values of five and seven B three.

Using the designated initialize, R have has the values of three and four and point before we can see

for ourselves that the Y data member was initialized with the value of 10, although it was done before

we initialized the value of X, which is still in this case.

Awesome.

Finally, we can take a look at five and five.

We said that we will initialize just part of its data members, so we initialize the AEC's data member

with the value of one, and we can see that the the other value for the other data member was.

Implicitly said to be zero.

Awesome.

So, yeah, this is it for these video guys, and now, you know, how to initialize.

Now you know how to initialize basically a variable of some structure.

In this case of a point struct.

OK, so this technique may be applied to various struct.

That's basically up to you to decide where it should be applied.

So as always, thank you guys for watching.

Keep on practicing.

Keep on moving forward and you are bound to succeed.

I'll see you next time.

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