Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.