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
OK, what is going on, guys?
And welcome back to our amazing programming course.
So in this video, we're going to talk about some new aspect that you are going to love.
I hope so.
So in C language, there is a way to create some shortcuts or some nicknames for different types of
definitions.
So, for example, we've talked about different grades, questions, and we've used to create different
like grades, variables.
Right.
So we used to create in grade one, in grade two, or even we used to create an array of integers,
just like end grades with five elements inside of it.
Now, there may be cases when we need to specify, even for some simplicity of the name of the course,
in the name of the course that you have these grades or grade one will be for physics and grade two
will be for math and so on.
OK, so you need to specify the name.
It's not sufficient just to use grade one, grade two because we do not know what do we refer to.
And one way to accomplish this task is to create the variables with the names of the course just like
that.
OK, so in great underscore math and grade under underscore physics, in this way you created two boxes.
OK, variable one variable to the name of the very the first variable in the name of the second variable.
And while that's good it will work.
OK, so what is typedef.
I think better.
Let's start with a simple example that will demonstrate us how it works.
So typedef end grade.
OK, so basically we have our first, the first time we see these typedef guy then we specify int and
grade OK and how basically it works.
We simply say that in every line that we are going to use from now on, in every line that we will use
the word grade with capital G are a d e ok.
It will be equivalent to as we've used this integer.
So instead of using it we will be able to use grade.
So for example, if we use grade math and grade physics, we will create two variables.
The first one, its name will be math and the second variable is going to be called physics.
So these two lines of code, OK?
It will also be possible to do it in just one line.
They are equivalent, equivalent, OK, and they are basically the same as these two lines.
OK, and this grade that we can see here is actually an integer.
Justin has some camouflage or I don't know how to say it.
It's just instead of these grade, we know that we after we wrote down this little line here at typedef
int grade, we said that every time after this line that we are going to use grade.
OK, just like that it will be equivalent, as we've used here, an integer.
And basically you may be asking yourself is why do why do we even need it, OK?
And they're telling the truth.
OK, there are some pros and cons, even at this level of programming, to use the typedef definition.
And I think that with a couple of examples, it will become much more clear to us as to how and why
exactly we want to use them.
But I see here that I just moved on and I want to let you know, just a quick explanation of why it
can be useful.
It is very useful even at this level of programming.
So suppose you are writing a program.
OK, so it's it will be much easier and much more readable for even for you as a programmer to understand
what are you meaning by that like integrate math.
OK, and if instead of that you would not have used in grade math, OK, because it's just a long variable
name and it may even also get much longer grade history or something like that.
It may be very long.
OK, because you want it is a descriptive variable, but I'm not sure that you should use such long
variable names in such a case.
So it will be very, very useful for you to take a look, OK, and to understand when you're reading
the code that this math variable, OK, math variable is of type grade.
And not not only that, it's of type grade, it's also, you know, that it should represent a grade,
OK, and you have one line when you see these equivalents if if it's either end float and so on.
So that's one usage, one pro in for using typedef at this level.
And if we will have time, I will give you also a couple of other explanations.
But I think for now it's it's fine enough because we are not going to learn everything you need else
in this section.
We want to move on with our structures.
So basically, why am I showing you these just now?
OK, well, the reason is very simple.
I think that these typedef type definition, OK, that's what happens behind the scenes.
The meaning is of great usage in the structures section that we currently study.
OK, so you remember we have this structure, a template like strike the date in day in month into year
and whatever.
We wanted to create a variable of this date type.
You always needed to write this struct date beforehand.
So it was something like that where it is.
No, it's not here.
So there was something we had to write to create the variable previously.
It was like struct.
OK, so Trachte date, struct date, we specified date and then we specified, for example, in this
case it was my date one.
OK, so that's how we created this variable of type struct date.
And I think it will be much easier and much nicer if instead of using these long struct to date, every
time you would want to create a date variable list, a date variable, instead of that, you will just
simply write something like that.
Date my date one day, my date to OK, I think it will be much easier or much more readable and much
nicer for you as a future programmer to have.
So what do you have to do for that is simply to use of a typedef.
OK, let's just remove it where it is.
Where is the eraser.
OK, so now what we are going to use is instead of creating our let's say let's use the blue color where
it is the blue one.
Nice.
So instead of using creating the template in this way struct date, we are going to create it a little
bit differently.
So this section.
OK, you can see it right here.
Right.
It's the same as it was here.
OK, so that's the same.
It's the same.
What we simply add here is the type dfki word, the type of definition and the new name, kind of the
new name we're giving to this type of definition.
So now we know that everywhere in our code, everywhere that we are going to use date.
OK, the key word date it will be equivalent is as we've used to date, just like you've seen here.
OK, so that's much shorter, much cleaner, and it will give you much more readability.
OK, so I hope that's clear to you guys.
And now let's take a look at a quick example of how we can work with structures.
OK, so first of all, let's create our print date function, OK?
And this function is very simple.
The type of the function.
OK, we know how it works.
The name of the function, nothing new print date and this date, OK?
It's part of the name of the function.
It does not have anything to do with the function of the with the structure type.
OK, that's just part of the function name.
And then we know that the function receives one value and this value is called variable is called DETI
and it's of type date of type, struct date.
All right.
And all what this function does is simply to print out the values, all of it, all of the fields of
this DETI variable.
So here equals the percentage, the monthly equal to percentage, the de equals the percentage the and
there you go.
Might add one dot here.
OK, dot is how you access a field in a given structure variable.
OK, so here, here I see we have a little bit of mistake instead of my date.
One, the name of the variable here is the T OK, so no worries about it guys.
That's something that I wanted to mention in another example where I showed where was the compilation
problem because in.
Didn't find the middle aged one, and I wanted to ask the students of why didn't it work?
So I think here it's a pretty good sense to to make sure that you understand it.
So instead of my state one, it would not this function wouldn't work because it might indeed.
One is not recognized in this scope.
Right.
I mean, it makes sense because who what is they might add one.
So we have here the variable DETI.
So here is the T dot here math and d d dot de so simple print of line that receives one argument of
a date structure type and this variable is called DETI and you simply print all the fields of this variable.
Pretty awesome guys.
And now let's take a look at how we also can create a function that will read inputs from the user.
OK, create a variable of these day type and also return return this new variable structure that was
created.
So it goes like this.
OK, so the function, name, input, date, it receives nothing.
OK, and it's type, its return type is a date.
So it was previously we used integer a floating point characters and now what we use is a new structure
and you type that is called date.
And all we do in this function is simply to create a new variable.
So in this line we created a new variable called DETI and it's of type date.
It doesn't have anything.
OK, the three here will be explained right away in this line.
He does not have anything OK.
All of its fields are on initialized.
And what we are going to do is to print through the screen, answer a day, OK, from one to thirty
one for example.
And the user is going to hit enter here to write down three Keat answer and then we are going to use
this kind of function to read this value using percentage these since we know it's an integer and to
store it inside of DETI Point Day.
OK, so in this field we will have these three value from the screen.
Amazing.
So you see guys how we are doing.
We created a new variable of this new structure div we accessed one of its fields and used this kind
of function to read the value from the user, from the console for example, and to store it inside
of these field.
So then we have another answer month, the same way reading the value from the user inputted.
It's inside of the month field.
Finally what we have is the year.
OK, so let's say twenty, twenty one and reading the value percentage are ampersands deti dot year.
So the variable year is the field storing it inside of these, of these fields.
OK, and once we are done, OK, we can see that we have here, this is our new variable and it's of
a new type and new structure type.
All of its fields are OK and are ready to go in our function simply using charge of creating this variable,
reading the values from the user, OK, and returning a copy of the structure we've just created.
So you simply return the T and you know that DTD of type date and you make sure that each of type date
and the signature corresponds to these type.
OK, guys, so you can see here all of these aspects.
Also when you're writing a program, make sure that whatever you return, you make sure that there is
a correspondence in the type of the return as well as the value that you've created.
So DTD of type date.
And that's why the return type is also of today day.
We specify that here.
We have also this is the previous thing that we spoke of.
It's not my date one, OK?
It's simply it's the same.
It's just the name of the variable.
It was used as part of additional explanation in one of our on different videos.
I don't think that I've added it here because it's kind of for another topic.
So there you go, guys.
And what we have created here is two functions.
One function that simply gets all the values for a date variable and returns it, and one function that
receives a date variable and prints it to the screen, prints all of its fields.
So that's amazing.
Guys, thank you for your attention.
Keep on practicing and keep on creating new variables with these.
Little new nice names, nicknames, shortcuts, using these typedef, give it a shot on your own, try
to run some code, make sure that you understand everything.
If you have any questions, feel free to ask them in the frequently asked questions and maybe somebody
has already answered it.
So until next time I'll see you then.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.