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
hu Hungarian Download
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
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,860 --> 00:00:01,860 All right. 2 00:00:01,880 --> 00:00:08,810 What is going on, ladies and gentlemen, and welcome to another video in our amazing programming course. 3 00:00:09,410 --> 00:00:16,070 And in this video, we are talking about how we can initialize a struct variable. 4 00:00:16,790 --> 00:00:23,750 But before we jump into initializing, let us, first of all, take a look at this tronc definition 5 00:00:23,750 --> 00:00:24,380 that we have. 6 00:00:25,450 --> 00:00:35,800 So what we have here is basically struct point with two fields index ending, why OK, simply two fields 7 00:00:36,010 --> 00:00:40,150 under the the roof of this new structure called point. 8 00:00:41,350 --> 00:00:48,160 And we are using the type of definition to specify that instead of using struct point to create different 9 00:00:48,160 --> 00:00:53,440 variables and work with data types of the new type struct point that we created. 10 00:00:53,830 --> 00:00:59,050 Instead of using that, we can use simply point with a Capital B in this example. 11 00:00:59,560 --> 00:01:06,880 OK, so point will be used to represent the type that we just created. 12 00:01:06,880 --> 00:01:11,980 This new type, this new user, a defined structure called point. 13 00:01:12,520 --> 00:01:13,000 All right. 14 00:01:13,540 --> 00:01:14,470 So far, so good. 15 00:01:14,830 --> 00:01:15,340 Awesome. 16 00:01:15,820 --> 00:01:19,540 So at this moment, we still don't have any instances of the variable. 17 00:01:19,810 --> 00:01:22,870 OK, any instances of the class point. 18 00:01:23,170 --> 00:01:29,560 But what we are going to do now is to see maybe once again how to declare a point variable. 19 00:01:29,920 --> 00:01:33,430 And basically how we can initialize in various ways. 20 00:01:34,030 --> 00:01:34,450 OK. 21 00:01:34,480 --> 00:01:35,890 So let us start. 22 00:01:37,360 --> 00:01:44,890 So the first thing that we are going to take a look at is of Eastpointe P1, and all he does is just 23 00:01:44,890 --> 00:01:49,210 to declare a point variable without any initialization. 24 00:01:49,810 --> 00:01:53,530 So if we will simply draw it, it will look like this. 25 00:01:53,860 --> 00:01:57,760 There will be p one and it's going to have two fields. 26 00:01:58,180 --> 00:02:04,180 The first member is the X, the second one is Y, and it has some garbage values inside of it. 27 00:02:04,660 --> 00:02:09,310 OK, so we simply created a bigger box called one with two members. 28 00:02:11,070 --> 00:02:17,400 The second option is initializing a point variable when members are in order. 29 00:02:18,270 --> 00:02:25,530 So we know that basically after just creating be one we could use, be one that X equals to some value 30 00:02:25,530 --> 00:02:30,030 and b y be one that y equals do some other value. 31 00:02:30,060 --> 00:02:30,420 Right. 32 00:02:30,690 --> 00:02:37,770 There is no problem using the assigning operation, but sometimes we would like to make the initialization 33 00:02:37,770 --> 00:02:38,520 right away. 34 00:02:39,120 --> 00:02:39,360 OK. 35 00:02:39,420 --> 00:02:41,880 Whenever we know the values themselves. 36 00:02:42,000 --> 00:02:48,210 So instead of spreading it into a couple of rows, we can just write it down in one comment. 37 00:02:49,290 --> 00:02:57,000 So in these command point B two and using the curly brackets, what we are getting is simply a variable 38 00:02:57,000 --> 00:02:58,050 called B2. 39 00:02:58,740 --> 00:03:01,110 It is of type, of course, point. 40 00:03:01,560 --> 00:03:08,850 And then whenever we use the curly brackets, we simply start feeling more, at least hoping to feel 41 00:03:08,850 --> 00:03:14,160 it, feeling the values for the data members of the struct. 42 00:03:14,490 --> 00:03:17,880 So we remember the first one is the second one is Y. 43 00:03:18,210 --> 00:03:23,400 So we simply put a value of five right here and seven right here. 44 00:03:23,610 --> 00:03:24,420 And there you go. 45 00:03:24,690 --> 00:03:31,350 You created your variable p with these two data members and these two values for each of them. 46 00:03:32,880 --> 00:03:33,240 OK. 47 00:03:34,050 --> 00:03:39,480 Another option for initialization is to use the designated initiate laser. 48 00:03:40,540 --> 00:03:48,720 So how it looks like we create a new variable called P3, it needs of type point, and these variable 49 00:03:48,720 --> 00:03:59,730 is going basically to be initialized with specifically or, let's say, explicitly specifying what members 50 00:03:59,760 --> 00:04:03,570 should have, what values at the initialization step. 51 00:04:04,350 --> 00:04:06,760 So we specify Dot X. 52 00:04:06,840 --> 00:04:11,510 It means, like we've written, P 3.6 equals two, three and B three. 53 00:04:11,520 --> 00:04:13,200 Dot Y equals two four. 54 00:04:14,190 --> 00:04:18,540 So basically, P3 is going to look like this. 55 00:04:20,560 --> 00:04:22,140 Three and four. 56 00:04:22,290 --> 00:04:24,180 That's the AEC's, and that's the way. 57 00:04:25,430 --> 00:04:25,880 OK. 58 00:04:26,360 --> 00:04:36,500 Designated initial her specifying exactly to what members of the class we want to put exactly what value. 59 00:04:36,950 --> 00:04:37,430 All right. 60 00:04:38,120 --> 00:04:38,630 Awesome. 61 00:04:39,770 --> 00:04:47,420 Now basically so far, we used all of the things in order, right, specifying first of all, the X 62 00:04:47,420 --> 00:04:48,200 and then the Y. 63 00:04:48,650 --> 00:04:52,640 But there may be times that we would like to specify, not in order. 64 00:04:53,360 --> 00:05:01,970 So this way we can always more basically, hopefully always try to look, try using the designated initial 65 00:05:01,970 --> 00:05:08,090 ICER and use the the values for each of the members in kind of out of order. 66 00:05:09,110 --> 00:05:16,640 So that means that we will not necessarily specify as the first value in this initial ICER. 67 00:05:17,420 --> 00:05:23,870 It doesn't necessarily have to be off a it doesn't necessarily have to be X. 68 00:05:24,080 --> 00:05:24,500 OK. 69 00:05:24,740 --> 00:05:30,710 We can specify that, first of all, we will specify the Y value and then the X OK. 70 00:05:30,710 --> 00:05:36,800 And basically what we will get is simply be for with the values of two and 10. 71 00:05:37,190 --> 00:05:37,670 OK. 72 00:05:38,540 --> 00:05:44,030 So that's just a side note for you to be familiar with any questions. 73 00:05:45,020 --> 00:05:45,320 Good. 74 00:05:45,770 --> 00:05:48,680 So now we use the designated initialize. 75 00:05:48,680 --> 00:05:52,370 The other members are initialized with zero. 76 00:05:52,820 --> 00:06:04,160 So this basically refers to the fact that whenever we create a variable of some user, a defined type, 77 00:06:04,760 --> 00:06:11,900 then we do not necessarily have to specify and to initialize all of its data members. 78 00:06:12,590 --> 00:06:18,350 OK, maybe sometimes we don't know what value should some some member have. 79 00:06:18,740 --> 00:06:25,280 So in this case, what we've done is basically we created P five and there are two fields. 80 00:06:25,370 --> 00:06:28,160 The first one is X and it has the value of one. 81 00:06:28,760 --> 00:06:30,650 And the second one is Y. 82 00:06:30,920 --> 00:06:35,720 And we will say that it will not be with an empty valley where some garbage value. 83 00:06:35,990 --> 00:06:42,680 We will say that by using these designated initialize, the other members that were not specified in 84 00:06:42,680 --> 00:06:49,400 this initialize or step will be initialized with the value of zero. 85 00:06:49,520 --> 00:06:50,750 So it will look like this. 86 00:06:51,920 --> 00:07:01,280 OK, so what we've done here is basically we've seen a couple of options to initialize a variable offer 87 00:07:01,280 --> 00:07:02,900 user defined type. 88 00:07:03,620 --> 00:07:10,880 In this case, it's very simple because we have only two fields of type end, but it does not necessarily 89 00:07:10,880 --> 00:07:11,960 have to be this way. 90 00:07:12,990 --> 00:07:20,700 We know that the fields, the members of a certain user defined struct, they may be also of different 91 00:07:20,700 --> 00:07:21,150 types. 92 00:07:21,900 --> 00:07:25,890 We may have a double, we may have a float, we may have a lot of other things. 93 00:07:27,670 --> 00:07:31,060 So we can also have a raise and so on and so forth. 94 00:07:32,210 --> 00:07:33,350 He doesn't really matter. 95 00:07:33,380 --> 00:07:41,210 Just make sure that whenever you initialize that the value you are trying to assign to a certain member 96 00:07:41,450 --> 00:07:42,830 that it simply makes sense. 97 00:07:44,040 --> 00:07:48,780 You would not want you would not want to take a string and to assign it to an integer. 98 00:07:49,230 --> 00:07:49,650 OK. 99 00:07:49,920 --> 00:07:52,590 And also probably not the other way around. 100 00:07:54,170 --> 00:07:54,500 Good. 101 00:07:54,770 --> 00:08:01,760 So the last thing that I want to do in this demonstration is basically, let's run. 102 00:08:03,480 --> 00:08:11,880 The debugger and see for ourselves how we can simply take a look at these five variables that we've 103 00:08:11,880 --> 00:08:21,780 created and what basically they hold so that this way you will know kind of more confident about the 104 00:08:21,780 --> 00:08:23,130 things that I've just mentioned. 105 00:08:23,940 --> 00:08:31,170 So if we take a look, we can see that here and the local section in the debugger, we are going to 106 00:08:31,200 --> 00:08:33,030 see all of the variables. 107 00:08:33,270 --> 00:08:38,850 OK, I'm simply using the debugging process, all of the variables that we've created because we are 108 00:08:38,850 --> 00:08:45,900 now at the last row in the main function and we can see B1, B2, B3, PS4 and PS5. 109 00:08:47,340 --> 00:08:52,500 And if we open them up, we will be able to see all the values inside of them. 110 00:08:52,980 --> 00:08:58,890 But also we can see it right here, the value for the field and the value for a field of wine, so be 111 00:08:58,890 --> 00:09:01,350 one is not initialized, right? 112 00:09:01,370 --> 00:09:04,500 You remember P1, one is not initialized with anything. 113 00:09:05,340 --> 00:09:13,140 So in this case, we simply have some garbage values inside of these X and Y data members. 114 00:09:14,010 --> 00:09:18,300 B two has the values of five and seven B three. 115 00:09:18,570 --> 00:09:26,160 Using the designated initialize, R have has the values of three and four and point before we can see 116 00:09:26,160 --> 00:09:35,040 for ourselves that the Y data member was initialized with the value of 10, although it was done before 117 00:09:35,040 --> 00:09:38,820 we initialized the value of X, which is still in this case. 118 00:09:39,990 --> 00:09:40,470 Awesome. 119 00:09:41,100 --> 00:09:44,730 Finally, we can take a look at five and five. 120 00:09:44,820 --> 00:09:52,110 We said that we will initialize just part of its data members, so we initialize the AEC's data member 121 00:09:52,110 --> 00:09:59,400 with the value of one, and we can see that the the other value for the other data member was. 122 00:10:00,380 --> 00:10:03,470 Implicitly said to be zero. 123 00:10:04,530 --> 00:10:04,940 Awesome. 124 00:10:06,150 --> 00:10:12,000 So, yeah, this is it for these video guys, and now, you know, how to initialize. 125 00:10:12,240 --> 00:10:17,960 Now you know how to initialize basically a variable of some structure. 126 00:10:18,950 --> 00:10:21,520 In this case of a point struct. 127 00:10:21,800 --> 00:10:25,160 OK, so this technique may be applied to various struct. 128 00:10:25,520 --> 00:10:29,810 That's basically up to you to decide where it should be applied. 129 00:10:30,500 --> 00:10:33,110 So as always, thank you guys for watching. 130 00:10:33,140 --> 00:10:34,430 Keep on practicing. 131 00:10:34,460 --> 00:10:38,300 Keep on moving forward and you are bound to succeed. 132 00:10:38,900 --> 00:10:39,800 I'll see you next time. 12716

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