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
Now, let us talk about the need and also the use it for unions.
OK, so I think the best thing we can do right now is to start with a simple example.
Let us see some code snippet with the syntax regarding unions and then discuss what's going on behind
the scenes.
So first of all, how we define a union.
So how to define to define a union, how we basically will define it in our programming language.
So first of all, we are going to use the union key word.
So that's going to look like this.
So, Union, OK, this this is a saved key word that will specify that now we are at the process of
defining the union and then we will specify the union name.
OK, here will be the union name that we will choose.
Okay.
I'm just showing you now the template.
That's not an actual definition because we will have to replace here these union names with a real name.
Now what we are going to do is to specify inside of these union some data type one.
OK, so data type one and field one and then data type two and field two and so on and so forth.
So field two and so on.
OK, so that's basically the definition of a union.
OK, that's the template.
And if we want to take a look at some example of how basically a real union can be defined, so let
us use something like this.
OK, so union, that's the first key word union and then we'll specify its name, let's say invoke.
And I will also say what will be its fields.
OK, so let's create an array of characters.
So Charr first name with 20 characters and also let's create additional variable, let's call it, I
don't know, age.
OK, so we created a union called Info and it has two fields.
The first field is first name and that's an array of characters of size 20.
And also we have age, which is an integer.
All right, so what do you also can do, you can create any other union that you want to know, union
or I don't know, mean remarks.
OK, I don't know something like this, Reverend.
Whatever you decide.
And here he is.
Two variables.
Oops.
Sorry about that.
Ain't mean and ain't MOCs and I don't know, double average.
I don't know.
Whatever you want you can use is as part of the fields of this union.
And we will see the differences between these unions to structures because there is a difference, there
is a difference.
And that's what we are going to discuss right now because of the creation of the union is pretty similar
to how we used strong.
Right.
Because we simply used here like struct in marks and then we created some fields.
So union definition, the definition of a union is very, very straight, very, very similar to the
structure, but is actually quite what has quite differences behind the scenes.
But before we do so, OK, before we do so, this first of all, just remove this, I don't know, this
template, OK, or basically let's go and do it.
Let's make that comment.
So this will be a long comment, but will specify the template for creating a union.
At least it will be some union that we will use for these examples.
OK, so now before we will proceed and dive into what's happening behind the scenes, I will also use
some drawing, some visualization to make it more clear to you.
What I want us to do now is just to focus on basically how we can create a variable of these user defined
type of this union that we just created, this union info.
So if we want to create a variable of some user, a defined union type, then in this case it will look
like this.
OK, so let's write also down the template.
OK, so that's the template of running it.
So first of all, you specify union and the union name, union the name, and then you specify also
the variable name.
OK, so that's basically the main template for creating a variable, OK, creating a variable template
for creating a union variable.
OK, a union that has already been defined.
So in our case we will simply use something like this.
So you need lenfilm union info and let's say, I don't know my variable, let's go with my variable,
my variable one.
So this will create a new variable called my variable one.
And it's going to be of type what type?
Union info.
OK, nothing special.
And these type, you know how it looks like behind the scenes.
Basically, that's its definition and how it really represented in terms of like visually we are going
to see right away.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.