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.
And now once you are done starting the basics, let's say, or the reason why you should even consider
using pointers in this video, we're going to talk about how to declare pointers and how to use pointers,
how it looks like when it's done in our C programming language.
So we've seen previously that although the changes between the values that we've made in this WAB function
when we passed by value did not have any effect on the variables in the main function.
So this approach didn't work and that means we need some way to set up some sort of a connection, a
reference between the actual variables we would like them to to get modified in the main function for,
for example, are A and B variables.
And we want that the function, this wolf function should should accomplish that.
Okay, we want that the swap function will take both of these A and B variables somehow some reference
to them.
And then once it's done executing, they will be simply swapped.
So we need a way to let this world function to access the actual variables in the main function, do
the whole swapping operation.
And after it's done, we will see the variables in the main actually swapped as expected.
And we said that it can be done through some sort of connection, some reference between the boxes residing
in one room to let these boxes to be accessed from another room just by using addresses.
Okay.
Just passing some actual coordinates of these variables, which in our case are the addresses.
And for that to do that.
To accomplish these tasks, we need to use our new friend called Pointers.
So now let's introduce how pointers are being used in our programming language.
And just a quick reminder, we can say that a standard variable, for example, in double char and so
on, is basically used to store some standard value.
Okay.
We call it this way standard variable, which we learned in the previous section, sections, stores,
some standard value.
So we may be using it to store integers char to store characteris and you've got the a.D.A basically.
So standard variable is used to store standard value.
And we can say for now that a pointer variable is of some unique type which contains instead of the
standard value as we are used previously.
It actually contains the address, it has the address of where it points to.
So for this Lavalin to make it more clearer to you guys, a pointer variable basically holds the address
of some standard variable.
Okay.
So how can we declare it?
How can we create our nice little pointer variable.
So it will look basically like this and star B.
OK.
inStar P and int we presents the data type actually represents the type of the data we will be pointing
to through these variable.
So in this case, we will point.
We will point.
We will hold the address where resides and end a variable.
So we will point to end and basically said that Pointer B points to an integer variable and simply states
that three, the value in the address you are pointing to as an integer.
So that's an important note for more advanced sections, although for a four for these course it's also
OK.
But it will be very useful for advanced courses as well.
All right.
So now we we can take a look at this new star.
OK, we we didn't see it previously.
And this star indicates that we are not using just the standard variable like we did.
We've done it with integers.
But we are working with some special.
OK.
Unique pointer.
Let's call it this way, OK?
And also we have lastly our P.
OK.
And P basically is just the name that we are giving to our pointer variable.
So basically we just created a variable called P that is a pointer of type integer.
It points to an integer variable to some either integer variable that we will assign it.
But but that's later on.
It's not in the declaration phase.
So to summarize, we have some rule to declare a pointer variable and it goes like this.
First of all, you specify the data type of there, the value that you want to that you know, you will
be pointing to.
Then you specify the star to to to say that it's of type pointer, four pointer type.
And then you specify as previously the very.
No name.
So that's it.
That's how you declare how you create a pointer in C programming language.
So now we can take a look at some other examples and see what what what will happen behind the scene,
which created a variable being the same box, similar box to what we've done.
We've used previously B, the name of the box.
It's just it's sticker and it says, I will hold the address, OK, later on.
Once we use some assignment operation, I will hold the end address.
And in this address that I will point to there.
I expect to see an integer variable and similarly can be done for double the BDD.
Just the name.
And it says I will point to some double and char b c, OK.
We basically can point also to character variables.
OK.
That's nothing are nothing new.
Basically just to understand the pointers declaration process.
So there are basically two main things you should keep in mind when using pointers.
The first thing is that you should keep in mind the new R address ampersand.
We've used it.
We've used it in this kind of functions.
But this ampersand simply specifies the address of a variable.
And we know that every variable has an address.
Right.
And P is a pointer.
OK.
If we have B, we created B is a pointer to an integer variable.
Thus we can say that p p we expect that it will have in the future when we make some assignment.
It will have the address of some other variable, for example, are a, b, num, whatever it was previous
location that it will have the address where it should, it should point to.
So remember these ampersand.
And remember the declaration state.
And if we take a look at this example.
OK.
If we create a variable and initialize a variable a..
Just like we've done previously in previous sections.
So in a equals two five, we just created a standard variable like a box called a R.
It has the value, a value of five.
And also it has some label, some specification of what what its address.
OK.
So it has its own unique address.
And now we can also create ar of the P variable.
The pointer variable.
Currently it's not initialized.
It does not point anywhere.
We should specify where these variables should point to.
So now, just to make a quick reminder, if you want to bring the value of variable.
You should simply use these print, print, off-line, ok.
So print F percentage the.
And the variable name.
OK.
It will print five to the screen.
And if you wanted to print the address of these variable of variable a the actual memory where it resides.
You should use print F percentage B and percent of a percent A specifies the address of A.
So four for if you run this example in your computer are the number.
Of course it's probably going to be different because when the place is the address where a variable
A resides and my computer may be different probably is going to be different than the address it resides
in your computer.
So this number that will be printed out or whatever format you're using specifies the address where
A resides.
So we can print the value of a variable A.
And also we can print and access and specify the address of variable H.
So please type down, write down these lines of code by yourself and check out how it works for you.
OK.
Make megaliths practice even if it's a little bit R now, but we'll practice it in the next challenges
and in the next videos.
But still try to also parse this video.
Right.
This print F percentage, the R A and print are also the address.
Just to feel it, just to understand what's going on behind the scenes.
OK.
And now once you're finished, let's get back to our example.
So basically, we created we created an Int variable, OK, into a equals two five.
That was initialized with some value.
And we also created a pointer, a variable called P.
We know that P is a pointer to end and it should point to any variable.
And since we didn't assign any address for appeared to point to OK, we didn't specify where P should
point to.
We can say that for now it points to nowhere.
OK.
Nothing.
Nothing to use for now.
And so we want to basically two point OK to to specify that P will point to variable A.
OK.
So we want B to point to A and for now it may not be so easy to understand why we even.
Want to do that and we'll put it in the logic, the main logic behind it.
But trust me, guys, everything will become clear as we proceed with this section.
And a lot of things will come when some time passes and you solve more and more exercises.
So for now, just relax and understand the main concept of pointing.
And what we want to do is to make be to point to a and we know that peace should hold and address of
the variable it's pointing to.
So basically what we are doing is specifying that P equals to the address of A..
OK.
So the logic is pretty simple.
OK, we want B to hold the address of the variable it points to.
So B equals two ampersand, A through the address of A..
So now it will hold as its value of the address of Fey and visually it with it would seem that it simply
points to a..
So by using B we can access variable A since we know all of its coordinates and we can test it out by
printing the address affair.
OK.
So let's bring the address of Fey and we are getting a triple threat.
Try this one also on your own.
And if you will, try also to print the value of.
OK.
You will see that both of them, both of them print the same result to the screen because, B, hold
the address of a..
OK.
And basically, that's that's the main concept for four pointers is is it the result that you're running?
Isn't.
Is it the same guys?
Is it the same for these two print off lines?
Try try this one on your own practice, please.
I, I, I'm asking you to feel how these line where you signed up.
P equals two on person A, how it feels like and understand deeply what's going on here.
So once you're done, we, we can move on to our last slide for this presentation.
It's called the referencing.
And we know that we can print the address of variable and that can be done using two ways, using our
print F percentage P and the address of A.
And also print P, the value of B, which is also the same.
And also we said that we can print the values of variable A and that's pretty nice line.
Will we know how to do it?
We just access the A variable and print its value.
But what I want to ask right now is how can we.
How can we print the value of a how can we access it?
Not by specifying the variable H itself, but rather accessing the variable A indirectly by using our
pointer variable P that simply points to A and has all of its information.
OK, because it can access its exact address.
So if we want to print the value of the variable that our pointer points to, it can be done using these
asterisks.
This, this Stara that we've created.
So what do we do with simply dereference a pointer to get the value that it points to?
So it looks like this.
So print F percentage the.
And these points are psr p we are going.
It can be translated and understood as we are going to the address that P points to and take these values
that is in this address.
And in this case it will be five.
So these printed flying, these slants, last print off-line will also print the value of a which is
five.
So the last two print defines are basically, we can say kind of identical.
They will print the same thing.
So we are accessing the value of baulks or variable A indirectly using the P pointer.
So that's also an important thing you should keep in mind when using pointers.
This usage of of the asterisk.
OK.
And once again, the meaning of it is that let's say it once again.
OK, go to the address that P points to and get the value that is stored there.
So I hope that's clear.
And with practice, you will feel much more confident.
And don't worry, we will cover up this topic and a lot of topics that will follow.
And also in advanced courses, we will talk about pointers.
And so don't worry.
You will understand pointers to their full list.
Maybe not nothing.
One hour of practicing, but with a lot of practice and a lot of hard work and a lot of lectures, we
will make it.
All right.
So thank you guys for watching.
And good luck.
LCN.
Next videos.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.