All language subtitles for 4. Unions - Going Further Additional Explanations and Examples

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,660 --> 00:00:04,500 All right, what is going on, ladies and gentlemen? 2 00:00:04,530 --> 00:00:07,140 Let me see that everything works as expected. 3 00:00:07,170 --> 00:00:07,730 Yes. 4 00:00:08,220 --> 00:00:15,840 So in this video, what we are going to do is to proceed with our tutorial and with our learning process 5 00:00:16,020 --> 00:00:19,200 of unions in C programming language. 6 00:00:19,710 --> 00:00:27,560 OK, so what we are going to do in this video is simply to see additional usage, additional structures 7 00:00:27,560 --> 00:00:33,380 or additional options of creating and working with unions. 8 00:00:33,390 --> 00:00:36,540 Maybe we will talk about type definition. 9 00:00:36,550 --> 00:00:42,300 We will talk about or maybe a pointer on a union type. 10 00:00:42,300 --> 00:00:51,420 And also we may also talk about a raise and let's see basically what this lecture will lead us to. 11 00:00:51,570 --> 00:01:00,580 So get yourself ready, get some something nice to drink and prepare yourself, because there we go. 12 00:01:00,810 --> 00:01:01,530 Let's do it. 13 00:01:02,550 --> 00:01:03,290 All right. 14 00:01:03,300 --> 00:01:07,110 So we are talking about unions, unions. 15 00:01:08,100 --> 00:01:14,220 And what I want us to do now is basically let's make a quick reminder of how we can define a union. 16 00:01:14,250 --> 00:01:18,330 OK, so basically saying let's create a union of a student. 17 00:01:18,340 --> 00:01:25,710 OK, so union student and let's use a couple of fields. 18 00:01:25,710 --> 00:01:27,060 What fields should we use? 19 00:01:27,420 --> 00:01:32,940 Let's use I don't know, let's use some I.D. and also let's use some GPA. 20 00:01:33,020 --> 00:01:39,270 OK, so two fields to values under this union student. 21 00:01:41,170 --> 00:01:45,150 And basically saying, what what do you think, what does it mean? 22 00:01:45,190 --> 00:01:49,300 OK, these two fields, it's going to make it more interesting and use here. 23 00:01:49,300 --> 00:01:51,200 I don't know, let's use double jeopardy. 24 00:01:51,400 --> 00:02:00,580 OK, so basically, you know what it is basically stands for a rating in education. 25 00:02:00,610 --> 00:02:06,900 OK, so that's just some sort of an average for those of you guys who is not familiar with it. 26 00:02:06,910 --> 00:02:13,810 So maybe for all of you guys, because you're coming from a lot of places, so double average. 27 00:02:14,170 --> 00:02:17,820 So to feel it and double average. 28 00:02:18,910 --> 00:02:20,770 So that's our union. 29 00:02:21,040 --> 00:02:21,560 OK. 30 00:02:21,610 --> 00:02:28,230 And basically we already know how we can create a variable of these type, so let's use it like this. 31 00:02:28,230 --> 00:02:34,150 So union student and let's make student one variable. 32 00:02:34,150 --> 00:02:41,590 So student one OK, and now we know that we can access and change any of its fields. 33 00:02:41,590 --> 00:02:45,690 But what do you think guys are actually happens behind the scenes? 34 00:02:46,120 --> 00:02:47,980 What do you think will be created now? 35 00:02:47,980 --> 00:02:56,050 So printout signs of student one union equals two, let's say percentage. 36 00:02:56,860 --> 00:03:04,360 And here use instead of these percentages, we will use size of size of student one. 37 00:03:04,960 --> 00:03:08,080 OK, so what do you think should be printed to the screen? 38 00:03:09,610 --> 00:03:13,600 Do you think a value of four should be printed? 39 00:03:13,610 --> 00:03:16,240 Do you think a value of eight should be printed? 40 00:03:16,240 --> 00:03:23,470 Do you think a value of four plus eight should be printed since we created this student one variable 41 00:03:23,470 --> 00:03:25,290 which is of type of union student? 42 00:03:25,300 --> 00:03:26,150 What do you think? 43 00:03:26,710 --> 00:03:32,170 So take a second, think about it and I'm going simply to execute it right away. 44 00:03:32,880 --> 00:03:37,750 Basically, you can see that the size of student one union equals to eight. 45 00:03:38,440 --> 00:03:40,750 And basically why why is that? 46 00:03:40,840 --> 00:03:42,890 Why is this happening? 47 00:03:43,870 --> 00:03:45,700 And the reason for that is very simple. 48 00:03:45,700 --> 00:03:47,060 We already talked about it. 49 00:03:47,680 --> 00:03:51,120 Let's just simply make a brief. 50 00:03:51,430 --> 00:03:57,970 So if we created student one, OK, so that's student one. 51 00:03:59,080 --> 00:04:00,040 That's the variable. 52 00:04:00,040 --> 00:04:08,170 STUDENT one And here it will have not both of these fields if it was like considering both of the fields. 53 00:04:08,170 --> 00:04:11,140 So it would be like four bytes plus eight. 54 00:04:11,140 --> 00:04:13,090 It would be a total of 12 bytes. 55 00:04:13,540 --> 00:04:21,430 But we simply get the memory for the largest element between these fields. 56 00:04:21,430 --> 00:04:26,440 And in this case, that's the double type and it consumes eight bytes of memory. 57 00:04:26,450 --> 00:04:36,100 So aid bytes of memory in this region in memory will be used to store either the I.D. or it will use 58 00:04:36,460 --> 00:04:38,270 be used to store the average. 59 00:04:38,290 --> 00:04:41,080 So one of them will be stored here. 60 00:04:41,440 --> 00:04:49,840 OK, that's in contrast to how the struct work, which basically you would have got here like two different 61 00:04:49,840 --> 00:04:55,850 and separate fields, ID and Everet, but that's something we already talked about in the previous menials. 62 00:04:55,870 --> 00:05:04,090 I just wanted to show you here how how this size of operator will work and how it will look like on 63 00:05:04,090 --> 00:05:05,110 this union. 64 00:05:06,120 --> 00:05:06,670 Awesome. 65 00:05:06,720 --> 00:05:16,140 So now we proceed and also talk about how we can create a pointer of a union type, so of course we 66 00:05:16,140 --> 00:05:23,370 can create a pointer because we just made this user defined new type and we can create a pointer just 67 00:05:23,370 --> 00:05:29,570 by using unión student and here specified, I don't know, PDR student two. 68 00:05:29,890 --> 00:05:35,190 OK, and we will say that BTR student two OK, is just a pointer. 69 00:05:35,370 --> 00:05:37,350 OK, what do you think will be the size. 70 00:05:37,770 --> 00:05:40,080 What do you think will be the size. 71 00:05:40,740 --> 00:05:46,250 What do you think will be the size of our PDR student too. 72 00:05:46,680 --> 00:05:47,150 OK. 73 00:05:47,190 --> 00:05:48,600 What do you think will be the size. 74 00:05:48,960 --> 00:05:49,940 Will it be eight. 75 00:05:50,120 --> 00:05:57,510 Again, just like the previous one, or basically will it be of a different value? 76 00:05:57,720 --> 00:06:04,940 OK, what do you think you should by this point, you should basically know the answer to it. 77 00:06:04,950 --> 00:06:11,730 And the answer is very straightforward because you know that every pointer is just the variable that 78 00:06:11,730 --> 00:06:19,900 should hold that should hold the address of where the actual variable with the actual value resides. 79 00:06:20,340 --> 00:06:25,950 And this type of pointer simply holds the address. 80 00:06:25,950 --> 00:06:29,430 And this address is specified by four bytes of memory. 81 00:06:29,430 --> 00:06:32,820 So it has nothing to do with these union type. 82 00:06:33,060 --> 00:06:37,700 It's basically a variable called PDR student to use. 83 00:06:38,310 --> 00:06:45,030 This variable is used to store the address of some union that we currently even do not point to. 84 00:06:45,810 --> 00:06:47,880 So I hope that's clear to you. 85 00:06:47,880 --> 00:06:53,900 And know, what we are going to do is basically to make some operations. 86 00:06:53,910 --> 00:07:02,400 We are going to say PDR student, OK, dot average or let's say it equals to five. 87 00:07:02,780 --> 00:07:09,240 OK, and we are going also now to print the value. 88 00:07:09,420 --> 00:07:16,380 OK, so print printout student one dot idee equals two percentage. 89 00:07:16,410 --> 00:07:20,670 Do we know that it can be printed out like this. 90 00:07:21,180 --> 00:07:21,660 OK. 91 00:07:23,630 --> 00:07:29,990 It can be printed out like this, so let's build and run it to make sure that everything works as expected. 92 00:07:30,230 --> 00:07:31,730 What's going on here? 93 00:07:32,330 --> 00:07:34,280 Oh, sorry about that. 94 00:07:35,000 --> 00:07:36,590 It's probably the problem. 95 00:07:37,310 --> 00:07:44,600 So, Keoki, something seems to not to be working as expected. 96 00:07:44,910 --> 00:07:48,700 Oh, so you will also have to fix it like here. 97 00:07:49,100 --> 00:07:54,820 So that's sort my my bad my bet I am that another down the road. 98 00:07:54,820 --> 00:08:00,860 Didn't that them see in what's going on. 99 00:08:02,570 --> 00:08:11,330 Um, oh, basically the problem is here, so we simply we simply haven't specified where the BTR students 100 00:08:11,480 --> 00:08:12,440 should point to. 101 00:08:13,130 --> 00:08:15,200 So you have done here a couple of mistakes. 102 00:08:15,230 --> 00:08:16,130 I'm sorry for that. 103 00:08:16,860 --> 00:08:18,810 Let's just fix that out, OK? 104 00:08:18,830 --> 00:08:24,290 So let's let's let's start from the scratch, because I think that that's not the best way to go. 105 00:08:24,290 --> 00:08:28,200 So meeting our students, you should have the address of student one, OK? 106 00:08:28,250 --> 00:08:30,790 And that's the way we use pointers. 107 00:08:30,800 --> 00:08:34,790 So now PDR student two points. 108 00:08:35,280 --> 00:08:39,440 OK, so it points to student one variable. 109 00:08:40,040 --> 00:08:41,220 Student one variable. 110 00:08:41,420 --> 00:08:41,790 Awesome. 111 00:08:42,320 --> 00:08:49,670 You know, let's use BTR student to basically not let's first of all, use just our student, one student 112 00:08:49,670 --> 00:08:52,410 one just to demonstrate what happens here. 113 00:08:52,430 --> 00:08:57,620 Student one equals two, what it should be equal to, let's say five. 114 00:08:57,680 --> 00:09:00,830 OK, and now print this value right here. 115 00:09:00,860 --> 00:09:03,770 OK, so let me get it straight. 116 00:09:03,920 --> 00:09:06,350 OK, here also. 117 00:09:06,640 --> 00:09:08,510 Now let's do it like this. 118 00:09:08,540 --> 00:09:15,020 OK, so now let's print student one I.D. just to show you that everything is working OK before. 119 00:09:15,080 --> 00:09:18,110 OK, that's before we are using the pointers. 120 00:09:18,140 --> 00:09:20,540 So let's build and run it and there you go. 121 00:09:20,540 --> 00:09:24,110 You can see that student one Darity equals two five. 122 00:09:24,350 --> 00:09:25,230 OK, awesome. 123 00:09:25,910 --> 00:09:30,700 Now let's try to change the side by using these BTR student two pointer. 124 00:09:30,860 --> 00:09:37,010 So your student, your student, let's say I d was to 210. 125 00:09:37,760 --> 00:09:50,030 Let's once again use this line to see what will happen after we changed it using the the pointer of 126 00:09:50,040 --> 00:09:51,200 PDR student two. 127 00:09:51,620 --> 00:09:52,760 So there you go. 128 00:09:52,760 --> 00:09:59,960 You can see that behind the scenes, BTR are student two has changed the value in the idea of student 129 00:09:59,960 --> 00:10:00,950 one already. 130 00:10:01,420 --> 00:10:06,500 So if we want to take a look at how it basically looks like behind the scenes. 131 00:10:06,540 --> 00:10:09,290 OK, so let's just remove this one, OK? 132 00:10:09,530 --> 00:10:14,120 So we created one variable called student one. 133 00:10:14,900 --> 00:10:15,830 Student one. 134 00:10:16,860 --> 00:10:19,920 And it's of tight union type of union. 135 00:10:19,950 --> 00:10:24,290 Union student, that's something we know so far. 136 00:10:25,020 --> 00:10:31,800 And we also created these PDR student, too, which is a variable of a pointer to union student type. 137 00:10:32,160 --> 00:10:35,220 OK, so that's PJR student to. 138 00:10:36,140 --> 00:10:44,990 And it basically points to these to these variable, and by using this pointer, we can simply also 139 00:10:44,990 --> 00:10:46,640 change its values. 140 00:10:46,940 --> 00:10:49,570 OK, so that's nothing new about pointers. 141 00:10:49,580 --> 00:10:52,300 That's probably something you already know by now. 142 00:10:52,940 --> 00:10:57,740 But just I wanted to demonstrate all of these all of this concept. 143 00:10:58,610 --> 00:10:59,150 Awesome. 144 00:11:00,510 --> 00:11:07,080 You know, last thing that I want to maybe last, maybe not to discussing this video is also that you 145 00:11:07,080 --> 00:11:14,730 can use here, like you can use typedef type definition unions, student and I don't know, let's call 146 00:11:14,730 --> 00:11:23,340 it Euromed, you know, instead of writing down like every time a union student and so on and so forth, 147 00:11:23,490 --> 00:11:31,200 you can simply use student, student and then specify student one or a student too. 148 00:11:31,350 --> 00:11:41,250 And these will basically create a union student user defined data type. 149 00:11:41,670 --> 00:11:47,690 And then you can access simply you remember how we used these typedef in our structures. 150 00:11:48,090 --> 00:11:50,520 So pretty much the same here. 151 00:11:50,820 --> 00:11:52,100 OK, awesome. 152 00:11:53,050 --> 00:11:57,140 Now, what also what else can we use here? 153 00:11:57,220 --> 00:11:58,670 What else can we use here? 154 00:11:58,690 --> 00:12:04,620 Let's try maybe to use oh, let's try to create an array of students, OK? 155 00:12:05,170 --> 00:12:08,000 Students, students are ready. 156 00:12:08,570 --> 00:12:16,100 OK, let's make it a size three and then we'll see that students are let's use and look. 157 00:12:16,330 --> 00:12:19,390 So in time let's go like this. 158 00:12:19,420 --> 00:12:22,210 So for all equals to zero. 159 00:12:22,720 --> 00:12:30,310 As long as I is less than three I plus plus at least case all you have to do is just to use to print 160 00:12:30,470 --> 00:12:34,000 out answer I.D. one. 161 00:12:36,410 --> 00:12:48,050 Then he is caniff percentage, the store, this value inside of students array at Index I and specify 162 00:12:48,050 --> 00:12:56,120 also dot d for example, I'm just showing you a few examples of how look what looks like a behind the 163 00:12:56,120 --> 00:12:56,660 scenes. 164 00:12:56,670 --> 00:13:08,270 So for angles now let's pretend I did not want a D let's say percentage D OK here specify I gave. 165 00:13:08,360 --> 00:13:11,000 So enter ID number see. 166 00:13:11,120 --> 00:13:12,860 Number one. 167 00:13:12,860 --> 00:13:13,610 Number two. 168 00:13:13,610 --> 00:13:14,420 Number three. 169 00:13:15,740 --> 00:13:16,240 Awesome. 170 00:13:16,730 --> 00:13:19,970 So printout here we will see that student. 171 00:13:21,810 --> 00:13:33,390 Student number percentage D, I guess it was two percentage dealing here with specified also, what 172 00:13:33,390 --> 00:13:34,320 should we specify? 173 00:13:34,710 --> 00:13:44,130 I plus one for these first I.D. number and for for these percentage which which numbers student reviews 174 00:13:44,550 --> 00:13:51,680 and also ID equals the percentage and that should be basically students array index. 175 00:13:51,690 --> 00:13:54,330 I got a D.. 176 00:13:54,690 --> 00:14:01,170 OK, so basically ah let's just check it out that everything works as expected. 177 00:14:01,170 --> 00:14:04,110 So inter I.D. number one, let's say five. 178 00:14:04,110 --> 00:14:07,280 Let's see, we are let's say 10 basically. 179 00:14:07,290 --> 00:14:07,860 There you go. 180 00:14:07,860 --> 00:14:10,500 Student number one ID equals to five. 181 00:14:10,500 --> 00:14:14,490 Student number two, it equals to three in student number three equals to. 182 00:14:15,390 --> 00:14:22,200 So basically you can see that you created an array of unions the way you created it this way. 183 00:14:22,650 --> 00:14:24,990 That's an array of unions. 184 00:14:25,800 --> 00:14:30,750 And what you've done here is basically two steps, three steps. 185 00:14:30,750 --> 00:14:36,720 First step was to create and define basically the union itself, union student. 186 00:14:37,050 --> 00:14:41,840 Then we used these type of definition to create these student nickname. 187 00:14:42,300 --> 00:14:47,940 And finally, the first step was like to create an array of students. 188 00:14:48,030 --> 00:14:57,000 And you simply specified the array name, the array size, and then you used some loop to you read inputs 189 00:14:57,000 --> 00:15:00,910 from the user and then you printed out all of these information. 190 00:15:01,080 --> 00:15:03,000 OK, so that's basically. 191 00:15:04,340 --> 00:15:14,300 A lot of our usages cover I cover tried to cover at least half the most useful information that you 192 00:15:14,450 --> 00:15:23,570 may actually be using on your exercises or basically on your exams or when your development using unions 193 00:15:23,570 --> 00:15:25,570 in our C programming language. 194 00:15:25,610 --> 00:15:27,680 So I hope everything is clear so far. 195 00:15:29,360 --> 00:15:33,040 And yeah, I guess this is it for these video guys. 196 00:15:33,080 --> 00:15:35,890 I hope this information will come in handy too. 197 00:15:35,890 --> 00:15:36,800 It will come handy to you. 198 00:15:37,640 --> 00:15:43,700 And until next time, keep practicing, keep them moving forward and we will see each other in the next 199 00:15:43,700 --> 00:15:44,170 videos. 200 00:15:44,300 --> 00:15:45,530 Until then, bye bye. 18668

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