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
Welcome back.
Ladies and gentlemen, to one of your most important and influencing topics in all of your programming
careers.
And in these section, as well as if you decide to study more advanced topics, pointers is something
that will definitely accompany you because it's actually the bases and the core for so many things in
programming as well as that's something that you're probably going to be asked on your C programming
interview questions.
So make sure you watch this topic from start till the end and practice that in the best possible way
you can.
So let's go.
I want us to make a quick reminder of the swab code we've used in one of our previous sections.
We simply wanted to take two variables into swap between their values and the main function.
Right.
So that was something like this.
We created our main function.
We initialized two variables into A equals two five, B equals two, seven and Vand.
To implement this swap operation, we just created another variable called temp.
We assign to temp A equals two, maybe equals 10.
Basically all the swap functionality we implemented in the main function.
It just looked like this.
And now since we already know how functions can be used in what for they are being used, we would like
to take this piece of code from the main function and put it inside some unique function and call these
function.
Just a swap.
OK.
Just to extract it out from the main function because we are already know how functions work.
We know that these swap functionality between two variables may be used more than just once.
Right.
It's usage may be required in many places in our program.
So that's why we would like to take these lines of code responsible for swapping and put them inside
a separate function.
So that now we will have all the responsibilities and all the code for the swap between two numbers
in just one place and not scatter it in many places in the main function.
And also, it will give us the ability to call this function whenever we would like to make some swap
operation.
Okay, so let's see how the code looks like in our C programming example.
And basically we see that we have a function of a volume type, the name of the function, a swap.
It has two values that it gets in one in two.
So we whenever we will call this function, we will give it two values.
One value will be assigned to number one and one value.
The second value will be assigned to number two.
Then what we are going to do is to create a temp variable that will assist us with on the swapping operation.
And we will print out now one before this WAP and NUM, two before the swap made the swap operation
the swap functionality and then print the values of number one and number two once again, just to make
sure that the swap works as expected.
So if we are to run this code right now, we will see on the console application that no one before
swap equals to five and num two equals to seven.
Right.
As expected, because we initialize it in the main function.
And also we will see that after the swap are we have number one equals to seven and number two equals
two five.
Everything works as expected.
So we have this while function, this WAP room that whenever we call this function, it will receive
two values and print them before the actual swap and after.
And this function will print this information on.
That's kind of a downside.
It will bring these information every time, every time we're going to call this function.
Are these two lines two four lines of this?
What are the values before and after will be printed?
And that's basically maybe something that we don't want.
Maybe you will want this one function just to swap between the values without printing them and to leave
maybe the printing onto another function and so on.
So we can say that sometimes we may want it and sometimes we may not want these two lines.
So let's just stick around with this one functionality for now.
Okay.
And let's see what will happen if we use these print lines in the function before and after.
Calling this what function?
Okay.
We will see it right away.
But basically, we we expect that the same result will will be seen on the screen that once on that,
once the swap function is over.
Then the variables in the main function will also be swapped and the messages will be seen on the screen.
Miskelly, what we want to do is not to put the print line.
The swap function, but rather to keep the printing, for example, in the main function, okay.
And swap function will be responsible for just swapping.
So let's try to do this and it will look like this.
Here is our void's swap.
It's responsible for swapping between number one and two.
And there you go.
You have the void main function.
So basically, it brings out the numbers before and after the swap.
And here we can see the function call a swap for A and B, and we just pass the values of A and B and
the are getting inside of number one and number two.
And if we wrong this program right now.
OK.
And you may just copy and run it on your own to see what happens.
You will see that nothing really happened.
It seems that the variables A and B and B were not swapped.
And that's a very important note that you must understand.
So y y basically it's happening, guys, y, A and B remain the same even after the call to this swap
function.
If it's done correctly here.
Right.
It's done basically correctly y of the result.
The printed A and B values seems to be the same, meaning A equals two five before and after the swap.
And it shouldn't be like that.
It should contain the value of B, which in this case is just seven after the swap.
But but it's not what happens.
OK.
Try to run it on your own just to make sure that you see the problem here.
So basically, although off for number one and number two, it seems that they were swapped inside the
swap function.
OK, so now one and two were swapped because they are local to the swap function.
But the actual A and B values, which are in the main function, which are values that we want to swap,
were Nance swap.
That's very interesting and that's the basis.
And one of the first and most important nodes explaining the reason of why you should consider using
pointers as well as what is passing by value and passing by reference that we are going to talk right
now.
So I hope that you are ready.
And in the next video, what we are going to do is that we are going to try and to visualize all of
these situation of this swapping and thoroughly understand what happened here and why it seems that
things were not working as expected.
And also, we are going then to describe and to to learn why we should consider using loops.
And when we should use it and how we should use it.
So don't worry.
This topic is not the easiest one.
But we will cover it.
I think pretty good.
So I'll see in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.