All language subtitles for custom_types-720p-en

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
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
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

DOUG LLOYD: So if you've seen our video on structures,

you already know that we have the ability to define our own data types.

But if you've used structures, you know that sometimes using those data types

can actually be a little cumbersome because we

have to use the struct keyword when we're working with them--

struct car or struct student.

That's a lot to type if we just want to have

something simple, like a structure.

We want to have-- we want to be able to work with things

a little more shorthand way, like int or char, something a lot

more convenient to type.

>> Fortunately, there's a way to do this in C,

with something called typedef, which is a way to create shorthand or rewritten

names for data types.

You can rewrite data types that already exist,

or you can write data types of your own.

>> The first thing you do is you define a type in the normal way,

and then you just alias it to something else-- typedef old name new name.

Pretty straightforward, right?

So we could typedef for example, the already existing data

type of unsigned char as byte.

And then, from now on, after we've made this type definition-- again,

which is usually going to be at the top of our dot C files, or in a dot H file

separately, we can just use bite everywhere

we would have used unsigned char.

That's a lot shorter to type.

>> In CS50's library, we do this-- we typedef char star as string.

Because we abstracted away the idea of pointers.

And the fact that a string is really a pointer to the first character--

an array of characters, because it's just

so confusing to get your head around that-- but in fact that's what we do.

And this line of code actually exists in CS50 dot H typedef char star string,

just to make that a little less cumbersome to have to deal with.

Already you've seen probably a little bit of the value here,

but typedef becomes great when combined with structures,

as I alluded to earlier.

Structures have a two-word type name.

And so they can be really annoying to create variables of that type,

or [INAUDIBLE] of struct something, your lines can just get really, really long.

And so you can use typedef to come up with something a lot shorter.

>> So if I define a car as follows, I have my definition of a car-- struct car,

and then open curly brace, all the fields of my structure,

close curly brace, semi-colon-- after I've defined my data type,

I can typedef struct car as car underscore t.

And then when I've done that, now every time I would have otherwise used struct

car, I can just use car underscore t.

That's a lot shorter of a way to express this idea of this structure

that I just created.

>> Alternatively, because structures are so commonly used in typedef,

there's a-- you can actually define the type in between the start and the end.

So the typedef structure again is usually typedef, old name, new name,

where the names are already types that you've created.

But you can actually define a structure right in the middle of the typedef

instead of having to define it separately, and then

do a typedef of it.

And that would look just like this-- typedef struct car,

open curly brace, all of your field definitions, close curly brace, car t.

So the old name is all that stuff in the red, you're just defining the structure

and naming it at the same time.

And then the new name is car underscore t.

And so if we start to use this in code, previously I

might have said, struct car mycar semi-colon.

Well I don't have to do that anymore.

Now that I've used the typedef, I can just say car underscore t, mycar.

That's a lot shorter of a way to do it, and in fact, it's

going to be a lot more convenient, especially

as you start to use structures a lot more in your code.

>> I'm Doug Lloyd.

This is CS50.

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