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.
So let's proceed with this WAB function and generally what we've sound about functions is that we may
think of them as some certain people with certain functionalities, or basically we can think of every
function as some sort of room or a lab which is responsible for the accomplishment of some task.
For example, we can see here that we have the driver, which is responsible for driving the painter,
the cooker and so on.
Right.
These are mainly our function or analogy, two functions.
And we also said that we can think of the main function as our current room is our main room.
And in this main room, we have two variables called A and B, which are just two boxes with the names
A and B, with the label C and B, and these two boxes sit in the main room.
Okay, we have the main room, the main function, and both of these variables just sitting there.
And also we've said that there is a swap function or we can say there is another room called Swap,
that there are seats.
Some guy who is responsible for this swap functionality between given two numbers that are answer to
to these these are swap room in the way we pass.
In this example, the two values from the main room to the swap room is accomplished not by sending
these boxes.
The boxes themselves are A and B, we do not send them, but rather we're just sending their values
a copy of their values.
For example, five and seven like we can see here if we initialize them to these values.
So by saying just sending their values, what we mean is simply sending some copy of these values.
So think of it this way.
If you would like to use this one function in the example we've seen previously.
Then when you call this one function, you would open the door of the other room of the swap room,
which is responsible for all the swapping functionality.
And you will not take the two boxes you have here in the main function and pass them to the swap room.
You just want take the boxes, but rather what you will do is just opening the door and screaming that
the two values should chair.
That should be changed are just five and seven.
Okay, so you're just passed by value.
Just a copy of these values, but not the boxes themselves.
You see the difference, and that's called passing by value.
So once again, you from the main you from the main room, you just screen the two values inside boxes,
A and B, and this is function.
Here is what you screen to it.
OK.
So I hear that the two numbers are five and seven.
And I store them inside of my two local variables, number one and number two, which are part of our
swap room.
Sophus, what function does not know anything about the variables in the main function?
He does not even it doesn't even know that they exist.
He just are in this what room gate takes a copy of them.
So I hope that's clear.
And now let's let's take a look at how on this what functionalities is this?
What function will work in this case?
OK.
So what happens inside of the swap function is something like this.
We create a temp variable.
We swap the values between the boxes of NUM one and, um, two.
And everything seems to be working as expected.
Right.
You can even try and print the values of number one and, um, two inside of the swap function.
And you will see that they were swapped as expected.
But in here comes the big but you can clearly see that the variables A and B in the main function remains
the same.
They didn't change.
It changed at all.
And basically, that's something that we we we didn't want.
Right.
We we wanted to change A and B, we didn't want to change number one in, um, to inside of some swap
room.
We wanted to see the result in the main room that A and B were swapped.
And at first glance, if we take, for example, the swap function, we think for to ourselves that
both of the rare variables should change.
But as we've said previously, we are passing through the swap function.
We are just passing a copy of these values of A and B. And now the variables themselves, not the boxes
themselves.
And then it means that we do not take these boxes A and B and swap between their content.
We are just working with a copy of its content of five and seven.
And it doesn't matter for a and being the main function.
So variables A and B remain untouched.
So let's take another look at this swap function and try to understand maybe.
The little bit further for what's going on here and maybe what should we do in this case, maybe the
pointers may help us, perhaps, right?
We are in the point resections.
So let's see what what do we have here?
So the code the code will look like this.
OK.
So we have this void swab.
OK.
The function does not return anything.
He just gets to values and it stores them inside of num one and um, two creates a temp for a temp variable
to assist in the swap functionality.
And then it does all its unnecessary things.
So what we expect once again, just to emphasize it, what we expect are it doesn't work clearly.
But what we want and what we expect that a functional will do is that we send it.
The variable is A and B, and it will return as this variable as it will make somehow that the values
in these two variables were changed from five to seven and from seven to five.
OK, and just by using these approaches that we have here and that we've seen here are simply won't
work.
And that's exactly when pointers enter the game.
So what we want to do is to pass the variables and be themselves or at least the way to access them
directly and not just the copy of their values.
Right.
Because if we want to change them, then what do we have to do is give some way to access them, the
real them, the real boxes, and not just a copy of A and B..
And what is that we know about variables that can really help us to identify them.
And you're you're right.
And we can see it right here on the screen.
Something special about variable, something unique is their address and and addresses some unique place
in the memory of your computer where the variable itself resides.
So that's a great way to access a given variable just by knowing where it seats.
OK.
It's just like where you live.
OK.
We can access where you live because we know your address.
So similarly, we can access variables in the memory of your computer just by using their address.
OK.
You should already know it by now.
But I'm just making a quick reminder.
And that summarizes that if at any point and any time we know the address of a variable, we can basically
directly access it and modified.
However we like.
Doesn't matter where we are accessing it from.
For me, for example, in the main functioning, the swap function, as long as we do it kind of legally.
All right.
So what we want to do is instead of calling this warb function and passing it a copy of the values which
we've seen previously, that it brings us pretty much nowhere.
What we would like to do is to pass the address of every variable, to pass the address of Variable
A and to pass the address of variable B.
And by doing so, this swap function will receive addresses of the specified variables.
And then just by knowing the address of where are some variable resides, we will use the concept of
pointers to access a given address.
And to do some things just just that this address to access these are variables through their address.
Is that clear?
And I know this concept is not so easy at first, but once you know the difference between these two
approaches, by sending by value and by reference, which which we are going to talk in these section
pointers will just become a piece of cake for you.
OK.
It will be so easy once you understand the logic and the core B behind what's happening in your computer
as memory and how you store values which hold addresses of other variables, which what we are exactly
doing right now.
I think that once you get this whole idea, maybe watch this video also twice just to emphasize and
to make sure you got everything that we said, because as I said previously, it's not so easy when
you hear this topic for the first time.
OK.
So now let's take another look and see how it works.
So we have the main function, OK?
And we have for two variables, A and B, both of them store some value.
A store is five has a value.
B stores seven is a value.
Think of it as just now.
I don't know.
Shoes.
The couple amount, the amount of shoes inside of these variables.
And also, we know we have this label of address, A, an address.
B, we also have an associated address where these variables reside in the memory of your computer.
So in this warped function, we have two parameters.
Let's call them p, num one and be numb to these variables.
What they have.
To do is simply to receive and store an address.
OK?
They will receive and store and dress that we pass to them.
OK.
They will hold addresses inside of them as their value.
That's something new.
We didn't talk about it in the previous sections.
And then when we pass the addresses to p num one and Piñon to OK, they will be held as values and they
will know OK.
They will know where the variables A and B are stored.
OK.
They will know how to access these variables.
Just by saying, OK, I know where they reside.
I can also access them.
OK.
Makes sense.
So by pointing to them, by pointing through B number one and piñon to two variables, A and B which
are inside of the main function.
So just by pointing from this WAB function to the main function variables, we will be able simply to
modify the content itself inside of these variables, A and B..
That's that's just awesome, guys.
You don't know how many topics.
How many are structures, programs, courses are built just on this understanding of pointers.
So these be No.
One and piñon two parameters that the swap function has are of a special type.
Let's say they let's call it this way because they do not hold.
Stand third are integer or a floating point type.
Worse, some some other value that we learned in the previous videos.
It simply stores an address.
So they hold addresses that in these addresses reside some values.
For example, five and seven in A and B and be No.
One holds the address of A and being on two holds the address of B.
They simply point somewhere.
And that's exactly why they here are called pointers.
Okay.
So I hope this animated and visualized explanation is clear to you guys.
I don't think that a lot of teachers really teach this tough topic, and that's a hell of a tough topic.
I don't think that a lot of teachers teach it this way.
And I know in my experience, in my opinion, that's why students are struggling to understand what
what is pointers and why we can use them.
But I think that this is the best approach to understand what's going on behind the scenes.
And I'll just do quit because it's too difficult to grasp it first.
So I hope that's clear because it's very important that you understand the topic.
It's the basis for the advanced sections and basically a lot of things are going to build to be built
upon it.
And this is it for these video.
Guys like screen is black.
We are over with this video.
I'll see you in the next one.
Have a nice day.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.