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
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, guys, so what I'm going to do now is a little bit tricky, and I want you to pay close attention
to what we are going to do next.
I'm going to create a function that is responsible for generating a dynamically allocated array and
also getting it from the user so it will go like this.
So instar generate generator rate and these are function is going to receive simply the size of the
array.
OK, very simple.
And what we are going to do here is to create a pointer into pointer error and we are going to say that
we are equals to inStar Mallock and basically the same things we've done and used in our previous memory
allocation things and so on.
So endpoints r r r r equals to install Ramallo at it, let's say.
Now we are also going to do something like that.
So receiving the values from the user.
So for I equals to zero, as long as I is less than let's say size.
Right.
And plus, plus that's it.
So as long as that's the case, let's use this kind of function to read the value from the user and
put it inside these allocated arrays.
So percentage D OK and put it inside a rather IT index I write.
So hopefully nothing complicated here and we understand what's happening and we are simply getting the
size of the array.
We want to allocate, we allocate these array of these specified size.
We iterate over all of it and initialize the elements in simply like reading the values from the user.
And finally, we simply return these array.
So return here.
That's it.
So instead of using these two static arrays, what we are going to do is to use some pointers.
So in error one and pointer error to write like that.
So that's what we are going to do.
And now what we are going also to do is call this function error.
One equals to generate array generator rate, let's say is off site.
Let's make it very generic.
Like to use here print f enter a size for array one.
Now we need also to do it for the second size of the arrows, for the size of the second array.
So enter size for Array two and read the value for size array two.
So that's it.
OK, so we got the sizes of the arrays that we want because we don't want to created static as it was
previous.
We want to make it dynamic and to let the user decide what should be the sizes of the arrays as well
as also above them, as well as also what do we want to do, as well as also letting the user the option
to specify the values of the array.
So here are one equals to generate what is a generates array.
And here we are going to specify size of array one and also eight or two equals to generate array and
specify size array to that's it.
So at this point we should already have two eraser error, one year two.
And we are going to do is instead of using this function of swap error and iterate over all the elements,
assuming that both of them are of the same size of Corsia, but instead of iterating over all of the
other elements, we are going to do a little trick here.
And what we are going to do is simply to create additional function and call this function void, void
swap swap array in just one constant operation.
Let's call it swap array, old one.
OK, guys, in what we are going to do in these function is simply to receive OK to receive some values
referred or related to these two arrays and to swap them in just one single swap operation.
So what do I mean by that instead of going and iterating over all the elements?
Right.
We know the address of the first element of in of the first element inside of this array and the first
element inside of that array.
So both of them we have here are one and a are two.
Both of them are simply variables.
Right.
We can see imagine them here.
So variable error, one a year or two.
And both of them are simply pointing to somewhere.
They both hold some address, OK, both of them have some address.
And what we are going to do is simply to let a r r one point from this point on, not the the allocated
array for error one, but to point to.
You are, too, and here are one and two is going to point to the values and the array allocated for
everyone.
So that's not very straightforward, but I think you've got the idea.
So we need to change the value inside of Iraq one and inside of Iraq to buy reference.
So we will send the addresses of these pointers.
Notice not the array themselves, not the address where they point to, but the address of the variables
here are one and area to themselves.
So we are going to send it to these function.
Let's call it a swap ratio of one.
We are going to send the address of Iraq one and the address of a or two.
That's what we are going to do.
And the address of a year or one is going to be received here.
So how should you receive it?
Basically, one way to do so is to get it as something like this and pointer, let's go like a Pityana,
let's call it Padawan and inStar BTR or two.
But in this case, we know that BTR one should point to integer, but we know that error one is not
a simple integer, it's a pointer to integer.
You can see it here then we need that BTR one will be a pointer to a pointer to integer.
So that's why we add additional asterisk here and that's how we point to the through the pointers that
basically point do the arrays allocate it so awesome.
And now what we have to do is simply to use another variable.
So let's use end are a temp, OK?
Because we are using Pointer Atem because temp is going to hold the address of where the array one of
the arrays is going to reside.
So that's why it's of a pointer to int you notice the difference between the original swap.
So Tampoe equals to Peter one and pointer BTR one is simply the value of error.
One, the value of error.
One is the address where the array error one currently resides.
And also we are going to do that for BTR.
Two equals two equals two.
No PDR one equals two points or Peter two.
And finally points are BTR two is going to be equal to temp.
So notice what we've done here.
We simply said that now instead of aira one pointing to the allocated array of error, one error, one
by reference, if we're using these PDR one and Piedra two for our help, he's going to point to the
of the other array and Pertierra two is going to end error.
Two is going to point to error, one to what it was pointing previously.
So that's what we've done behind the scenes, guys, in just one operation without taking into consideration
how and what will be the size of each of these arrays.
And one thing that also can be done here is since we you already know the type and the general type,
instead of using it, we could have just simply used void here because it's a universal type.
We are working just with addresses and we don't really care if it's a point or two points or two.
And it's we can use it just as a universal abstraction, this given function who.
So I hope you got it clear.
Maybe I will add some also visualizations for you to understand this concept.
And basically, if you have any questions, feel free to ask.
We will do our best to respond to your questions on my recommendation is before you jump and move on
and even write this code on your own, write down these function.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.