All language subtitles for 5. Typedef & Structures

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,180 --> 00:00:02,280 OK, what is going on, guys? 2 00:00:02,310 --> 00:00:06,030 And welcome back to our amazing programming course. 3 00:00:06,810 --> 00:00:14,310 So in this video, we're going to talk about some new aspect that you are going to love. 4 00:00:14,730 --> 00:00:15,420 I hope so. 5 00:00:15,840 --> 00:00:26,340 So in C language, there is a way to create some shortcuts or some nicknames for different types of 6 00:00:26,340 --> 00:00:27,300 definitions. 7 00:00:27,570 --> 00:00:35,310 So, for example, we've talked about different grades, questions, and we've used to create different 8 00:00:35,520 --> 00:00:37,380 like grades, variables. 9 00:00:37,380 --> 00:00:37,750 Right. 10 00:00:38,130 --> 00:00:44,940 So we used to create in grade one, in grade two, or even we used to create an array of integers, 11 00:00:45,030 --> 00:00:49,020 just like end grades with five elements inside of it. 12 00:00:49,110 --> 00:00:57,240 Now, there may be cases when we need to specify, even for some simplicity of the name of the course, 13 00:00:57,600 --> 00:01:04,860 in the name of the course that you have these grades or grade one will be for physics and grade two 14 00:01:04,860 --> 00:01:06,740 will be for math and so on. 15 00:01:06,750 --> 00:01:08,790 OK, so you need to specify the name. 16 00:01:08,790 --> 00:01:16,730 It's not sufficient just to use grade one, grade two because we do not know what do we refer to. 17 00:01:16,770 --> 00:01:24,750 And one way to accomplish this task is to create the variables with the names of the course just like 18 00:01:24,750 --> 00:01:25,230 that. 19 00:01:25,380 --> 00:01:32,690 OK, so in great underscore math and grade under underscore physics, in this way you created two boxes. 20 00:01:32,700 --> 00:01:40,050 OK, variable one variable to the name of the very the first variable in the name of the second variable. 21 00:01:40,200 --> 00:01:43,450 And while that's good it will work. 22 00:01:43,470 --> 00:01:46,350 OK, so what is typedef. 23 00:01:46,350 --> 00:01:47,290 I think better. 24 00:01:47,310 --> 00:01:52,200 Let's start with a simple example that will demonstrate us how it works. 25 00:01:53,040 --> 00:01:55,530 So typedef end grade. 26 00:01:55,710 --> 00:02:04,700 OK, so basically we have our first, the first time we see these typedef guy then we specify int and 27 00:02:04,920 --> 00:02:07,830 grade OK and how basically it works. 28 00:02:08,310 --> 00:02:15,690 We simply say that in every line that we are going to use from now on, in every line that we will use 29 00:02:15,690 --> 00:02:21,240 the word grade with capital G are a d e ok. 30 00:02:21,300 --> 00:02:25,740 It will be equivalent to as we've used this integer. 31 00:02:25,740 --> 00:02:29,400 So instead of using it we will be able to use grade. 32 00:02:29,490 --> 00:02:36,150 So for example, if we use grade math and grade physics, we will create two variables. 33 00:02:36,570 --> 00:02:42,200 The first one, its name will be math and the second variable is going to be called physics. 34 00:02:42,330 --> 00:02:45,330 So these two lines of code, OK? 35 00:02:45,360 --> 00:02:48,810 It will also be possible to do it in just one line. 36 00:02:49,090 --> 00:02:55,780 They are equivalent, equivalent, OK, and they are basically the same as these two lines. 37 00:02:55,800 --> 00:03:01,250 OK, and this grade that we can see here is actually an integer. 38 00:03:01,290 --> 00:03:05,480 Justin has some camouflage or I don't know how to say it. 39 00:03:05,730 --> 00:03:12,900 It's just instead of these grade, we know that we after we wrote down this little line here at typedef 40 00:03:12,900 --> 00:03:19,260 int grade, we said that every time after this line that we are going to use grade. 41 00:03:19,320 --> 00:03:24,330 OK, just like that it will be equivalent, as we've used here, an integer. 42 00:03:24,330 --> 00:03:30,610 And basically you may be asking yourself is why do why do we even need it, OK? 43 00:03:31,020 --> 00:03:32,760 And they're telling the truth. 44 00:03:32,790 --> 00:03:40,020 OK, there are some pros and cons, even at this level of programming, to use the typedef definition. 45 00:03:40,320 --> 00:03:48,420 And I think that with a couple of examples, it will become much more clear to us as to how and why 46 00:03:48,420 --> 00:03:50,580 exactly we want to use them. 47 00:03:50,580 --> 00:03:58,070 But I see here that I just moved on and I want to let you know, just a quick explanation of why it 48 00:03:58,080 --> 00:03:59,000 can be useful. 49 00:03:59,040 --> 00:04:02,180 It is very useful even at this level of programming. 50 00:04:02,490 --> 00:04:04,820 So suppose you are writing a program. 51 00:04:04,830 --> 00:04:12,690 OK, so it's it will be much easier and much more readable for even for you as a programmer to understand 52 00:04:12,780 --> 00:04:16,410 what are you meaning by that like integrate math. 53 00:04:16,420 --> 00:04:24,060 OK, and if instead of that you would not have used in grade math, OK, because it's just a long variable 54 00:04:24,060 --> 00:04:29,550 name and it may even also get much longer grade history or something like that. 55 00:04:29,970 --> 00:04:31,440 It may be very long. 56 00:04:31,440 --> 00:04:39,580 OK, because you want it is a descriptive variable, but I'm not sure that you should use such long 57 00:04:39,760 --> 00:04:41,580 variable names in such a case. 58 00:04:41,820 --> 00:04:52,200 So it will be very, very useful for you to take a look, OK, and to understand when you're reading 59 00:04:52,200 --> 00:04:59,490 the code that this math variable, OK, math variable is of type grade. 60 00:04:59,980 --> 00:05:07,900 And not not only that, it's of type grade, it's also, you know, that it should represent a grade, 61 00:05:08,000 --> 00:05:15,260 OK, and you have one line when you see these equivalents if if it's either end float and so on. 62 00:05:15,580 --> 00:05:23,260 So that's one usage, one pro in for using typedef at this level. 63 00:05:23,440 --> 00:05:29,070 And if we will have time, I will give you also a couple of other explanations. 64 00:05:29,080 --> 00:05:36,480 But I think for now it's it's fine enough because we are not going to learn everything you need else 65 00:05:36,520 --> 00:05:37,650 in this section. 66 00:05:37,780 --> 00:05:41,520 We want to move on with our structures. 67 00:05:42,130 --> 00:05:46,340 So basically, why am I showing you these just now? 68 00:05:46,360 --> 00:05:48,670 OK, well, the reason is very simple. 69 00:05:48,700 --> 00:05:54,580 I think that these typedef type definition, OK, that's what happens behind the scenes. 70 00:05:54,580 --> 00:06:00,190 The meaning is of great usage in the structures section that we currently study. 71 00:06:00,340 --> 00:06:07,210 OK, so you remember we have this structure, a template like strike the date in day in month into year 72 00:06:07,480 --> 00:06:08,860 and whatever. 73 00:06:08,860 --> 00:06:12,460 We wanted to create a variable of this date type. 74 00:06:12,490 --> 00:06:16,780 You always needed to write this struct date beforehand. 75 00:06:16,780 --> 00:06:19,470 So it was something like that where it is. 76 00:06:19,480 --> 00:06:20,340 No, it's not here. 77 00:06:20,500 --> 00:06:25,600 So there was something we had to write to create the variable previously. 78 00:06:25,600 --> 00:06:27,250 It was like struct. 79 00:06:27,280 --> 00:06:35,680 OK, so Trachte date, struct date, we specified date and then we specified, for example, in this 80 00:06:35,680 --> 00:06:38,920 case it was my date one. 81 00:06:39,100 --> 00:06:43,630 OK, so that's how we created this variable of type struct date. 82 00:06:43,840 --> 00:06:52,960 And I think it will be much easier and much nicer if instead of using these long struct to date, every 83 00:06:52,960 --> 00:06:59,170 time you would want to create a date variable list, a date variable, instead of that, you will just 84 00:06:59,170 --> 00:07:01,180 simply write something like that. 85 00:07:01,240 --> 00:07:08,470 Date my date one day, my date to OK, I think it will be much easier or much more readable and much 86 00:07:08,650 --> 00:07:12,350 nicer for you as a future programmer to have. 87 00:07:12,370 --> 00:07:16,760 So what do you have to do for that is simply to use of a typedef. 88 00:07:16,780 --> 00:07:20,820 OK, let's just remove it where it is. 89 00:07:20,830 --> 00:07:22,120 Where is the eraser. 90 00:07:22,150 --> 00:07:31,780 OK, so now what we are going to use is instead of creating our let's say let's use the blue color where 91 00:07:31,780 --> 00:07:33,130 it is the blue one. 92 00:07:33,520 --> 00:07:33,940 Nice. 93 00:07:34,330 --> 00:07:41,740 So instead of using creating the template in this way struct date, we are going to create it a little 94 00:07:41,740 --> 00:07:42,910 bit differently. 95 00:07:42,910 --> 00:07:44,440 So this section. 96 00:07:44,480 --> 00:07:46,960 OK, you can see it right here. 97 00:07:46,960 --> 00:07:47,260 Right. 98 00:07:47,360 --> 00:07:49,670 It's the same as it was here. 99 00:07:49,690 --> 00:07:51,790 OK, so that's the same. 100 00:07:51,790 --> 00:07:52,510 It's the same. 101 00:07:52,990 --> 00:08:01,480 What we simply add here is the type dfki word, the type of definition and the new name, kind of the 102 00:08:01,480 --> 00:08:04,620 new name we're giving to this type of definition. 103 00:08:04,660 --> 00:08:12,110 So now we know that everywhere in our code, everywhere that we are going to use date. 104 00:08:12,200 --> 00:08:20,500 OK, the key word date it will be equivalent is as we've used to date, just like you've seen here. 105 00:08:20,650 --> 00:08:27,730 OK, so that's much shorter, much cleaner, and it will give you much more readability. 106 00:08:28,300 --> 00:08:30,390 OK, so I hope that's clear to you guys. 107 00:08:30,580 --> 00:08:39,340 And now let's take a look at a quick example of how we can work with structures. 108 00:08:39,730 --> 00:08:45,840 OK, so first of all, let's create our print date function, OK? 109 00:08:45,850 --> 00:08:47,590 And this function is very simple. 110 00:08:47,590 --> 00:08:48,790 The type of the function. 111 00:08:48,890 --> 00:08:50,400 OK, we know how it works. 112 00:08:50,710 --> 00:08:56,380 The name of the function, nothing new print date and this date, OK? 113 00:08:56,530 --> 00:08:58,640 It's part of the name of the function. 114 00:08:58,640 --> 00:09:02,860 It does not have anything to do with the function of the with the structure type. 115 00:09:02,910 --> 00:09:05,170 OK, that's just part of the function name. 116 00:09:05,710 --> 00:09:12,490 And then we know that the function receives one value and this value is called variable is called DETI 117 00:09:12,700 --> 00:09:16,490 and it's of type date of type, struct date. 118 00:09:16,510 --> 00:09:17,320 All right. 119 00:09:17,320 --> 00:09:25,990 And all what this function does is simply to print out the values, all of it, all of the fields of 120 00:09:25,990 --> 00:09:27,810 this DETI variable. 121 00:09:27,820 --> 00:09:33,940 So here equals the percentage, the monthly equal to percentage, the de equals the percentage the and 122 00:09:33,940 --> 00:09:34,510 there you go. 123 00:09:34,510 --> 00:09:36,190 Might add one dot here. 124 00:09:36,200 --> 00:09:40,810 OK, dot is how you access a field in a given structure variable. 125 00:09:40,840 --> 00:09:46,120 OK, so here, here I see we have a little bit of mistake instead of my date. 126 00:09:46,120 --> 00:09:50,680 One, the name of the variable here is the T OK, so no worries about it guys. 127 00:09:50,770 --> 00:09:58,420 That's something that I wanted to mention in another example where I showed where was the compilation 128 00:09:58,750 --> 00:09:59,890 problem because in. 129 00:09:59,920 --> 00:10:06,320 Didn't find the middle aged one, and I wanted to ask the students of why didn't it work? 130 00:10:06,340 --> 00:10:12,680 So I think here it's a pretty good sense to to make sure that you understand it. 131 00:10:12,730 --> 00:10:18,250 So instead of my state one, it would not this function wouldn't work because it might indeed. 132 00:10:18,250 --> 00:10:20,860 One is not recognized in this scope. 133 00:10:20,860 --> 00:10:21,220 Right. 134 00:10:21,220 --> 00:10:24,300 I mean, it makes sense because who what is they might add one. 135 00:10:24,580 --> 00:10:27,100 So we have here the variable DETI. 136 00:10:27,130 --> 00:10:38,110 So here is the T dot here math and d d dot de so simple print of line that receives one argument of 137 00:10:38,110 --> 00:10:46,990 a date structure type and this variable is called DETI and you simply print all the fields of this variable. 138 00:10:46,990 --> 00:10:48,190 Pretty awesome guys. 139 00:10:48,400 --> 00:10:56,950 And now let's take a look at how we also can create a function that will read inputs from the user. 140 00:10:57,130 --> 00:11:05,950 OK, create a variable of these day type and also return return this new variable structure that was 141 00:11:05,950 --> 00:11:06,750 created. 142 00:11:06,790 --> 00:11:08,030 So it goes like this. 143 00:11:08,050 --> 00:11:12,100 OK, so the function, name, input, date, it receives nothing. 144 00:11:12,160 --> 00:11:15,910 OK, and it's type, its return type is a date. 145 00:11:15,910 --> 00:11:25,180 So it was previously we used integer a floating point characters and now what we use is a new structure 146 00:11:25,180 --> 00:11:27,310 and you type that is called date. 147 00:11:27,850 --> 00:11:32,280 And all we do in this function is simply to create a new variable. 148 00:11:32,290 --> 00:11:38,010 So in this line we created a new variable called DETI and it's of type date. 149 00:11:38,020 --> 00:11:39,460 It doesn't have anything. 150 00:11:39,460 --> 00:11:43,270 OK, the three here will be explained right away in this line. 151 00:11:43,270 --> 00:11:45,480 He does not have anything OK. 152 00:11:45,610 --> 00:11:48,520 All of its fields are on initialized. 153 00:11:48,610 --> 00:11:54,520 And what we are going to do is to print through the screen, answer a day, OK, from one to thirty 154 00:11:54,520 --> 00:11:55,480 one for example. 155 00:11:55,900 --> 00:12:02,710 And the user is going to hit enter here to write down three Keat answer and then we are going to use 156 00:12:02,950 --> 00:12:09,220 this kind of function to read this value using percentage these since we know it's an integer and to 157 00:12:09,220 --> 00:12:12,920 store it inside of DETI Point Day. 158 00:12:12,940 --> 00:12:17,640 OK, so in this field we will have these three value from the screen. 159 00:12:17,660 --> 00:12:18,540 Amazing. 160 00:12:18,550 --> 00:12:20,800 So you see guys how we are doing. 161 00:12:20,800 --> 00:12:28,420 We created a new variable of this new structure div we accessed one of its fields and used this kind 162 00:12:28,420 --> 00:12:34,450 of function to read the value from the user, from the console for example, and to store it inside 163 00:12:34,450 --> 00:12:35,700 of these field. 164 00:12:35,980 --> 00:12:43,330 So then we have another answer month, the same way reading the value from the user inputted. 165 00:12:43,330 --> 00:12:46,040 It's inside of the month field. 166 00:12:46,190 --> 00:12:48,890 Finally what we have is the year. 167 00:12:48,910 --> 00:12:56,410 OK, so let's say twenty, twenty one and reading the value percentage are ampersands deti dot year. 168 00:12:56,560 --> 00:13:01,580 So the variable year is the field storing it inside of these, of these fields. 169 00:13:02,060 --> 00:13:10,060 OK, and once we are done, OK, we can see that we have here, this is our new variable and it's of 170 00:13:10,060 --> 00:13:13,060 a new type and new structure type. 171 00:13:13,240 --> 00:13:21,430 All of its fields are OK and are ready to go in our function simply using charge of creating this variable, 172 00:13:21,550 --> 00:13:30,570 reading the values from the user, OK, and returning a copy of the structure we've just created. 173 00:13:30,820 --> 00:13:38,770 So you simply return the T and you know that DTD of type date and you make sure that each of type date 174 00:13:38,920 --> 00:13:43,720 and the signature corresponds to these type. 175 00:13:44,020 --> 00:13:48,130 OK, guys, so you can see here all of these aspects. 176 00:13:48,130 --> 00:13:53,710 Also when you're writing a program, make sure that whatever you return, you make sure that there is 177 00:13:53,710 --> 00:13:58,360 a correspondence in the type of the return as well as the value that you've created. 178 00:13:58,360 --> 00:14:00,220 So DTD of type date. 179 00:14:00,340 --> 00:14:03,760 And that's why the return type is also of today day. 180 00:14:03,760 --> 00:14:05,800 We specify that here. 181 00:14:05,800 --> 00:14:09,580 We have also this is the previous thing that we spoke of. 182 00:14:09,580 --> 00:14:11,320 It's not my date one, OK? 183 00:14:11,320 --> 00:14:13,420 It's simply it's the same. 184 00:14:13,420 --> 00:14:15,160 It's just the name of the variable. 185 00:14:15,280 --> 00:14:21,490 It was used as part of additional explanation in one of our on different videos. 186 00:14:21,490 --> 00:14:26,860 I don't think that I've added it here because it's kind of for another topic. 187 00:14:27,070 --> 00:14:28,710 So there you go, guys. 188 00:14:28,720 --> 00:14:32,140 And what we have created here is two functions. 189 00:14:32,320 --> 00:14:41,980 One function that simply gets all the values for a date variable and returns it, and one function that 190 00:14:42,280 --> 00:14:49,660 receives a date variable and prints it to the screen, prints all of its fields. 191 00:14:50,530 --> 00:14:51,840 So that's amazing. 192 00:14:51,850 --> 00:14:54,160 Guys, thank you for your attention. 193 00:14:54,400 --> 00:14:59,680 Keep on practicing and keep on creating new variables with these. 194 00:15:00,210 --> 00:15:07,250 Little new nice names, nicknames, shortcuts, using these typedef, give it a shot on your own, try 195 00:15:07,320 --> 00:15:10,310 to run some code, make sure that you understand everything. 196 00:15:10,340 --> 00:15:17,000 If you have any questions, feel free to ask them in the frequently asked questions and maybe somebody 197 00:15:17,000 --> 00:15:18,560 has already answered it. 198 00:15:19,130 --> 00:15:21,170 So until next time I'll see you then. 19478

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