Hello everyone, my name is (name) and we are continuing with this C programming course.
In the last video we had discussed pointers with functions.
In that video we had seen how our pointer is pointing at a function, which means the address of the function where it is getting stored.
That address we can store in our pointer.
In this video we will be seeing some more pointers.
The pointers that we saw were pointing at the variables or at the functions, apart from that, these pointers have been divided into various characteristics based on the properties.
Our pointer is pointed to what, the value that is getting stored in it, what type who that be, based on all these things we are categorising out pointers in different ways.
In this video we will be seeing three such types of pointers which are a little more important in C programming.
And it is very necessary for us to know about these concepts because all these things also we'll be using in our program.
So, we will go ahead and first of all we will see which are those three pointers which we will be discussing here in this video.
If I talk about those three pointers, the first pointer which we will use that would be null pointer.
What is this null pointer? What does this mean? We will discuss it in the coming slides but for now, let's understand first of all, we will discuss the null pointer then we will see the void pointer and at the end we will be seeing a wild pointer.
What exactly are these pointers and how are they different from each other? That we will see going ahead in the next slide.
First of all, we will discuss the null pointer.
What exactly is this null pointer that we will understand here.
It is created by assigning the null value at the time of pointer declaration.
So, when we declare the pointer, we are writing it as a data type.
Along with that we also put an asterisk mark on it, with which we get to know that this is a pointer, at the same time, when we are assigning few values to that particular pointer.
Instead of assigning to something else, we will assign it to a certain null value.
Which means if the null value gets stored in it, while pointing so in that situation, that pointer is called as null pointer what does this mean? If the variable was pointing at a certain variable or function, then we would have accessed that function with our pointer but what exactly happens in the null pointer? It is pointing at null.
Null here means nothing.
Okay, so null in our programming language, which is spelled as N U L L, null means that it is not pointing anywhere.
There's no pointing at any variable or any function, what happens with this.
The exact address that is getting stored in it, whenever it used to point at a certain variable or function, the address that used to get stored that is not getting stored over here.
Why? because it is pointing at null.
It is not pointing at anything.
That is why the value that is getting stored in it.
The exact value, that is zero.
So, the null pointer is not pointing at anything.
It points at null, that's why the value stored in it is zero.
You might not understand it very much.
After understanding it theoretically, we will also use it practically and see how we are making one null pointer but before that we will cover the other pointers and all three, we will see in our text editor.
So now we will move ahead, after the null pointer comes the void pointer.
What is this void pointer? It is a pointer that has no associated data type with it.
So, if I talk about the pointer along with that, we have to write the data type and what should that data type match with? Whichever thing’s address we are storing in our pointer, we must match its data type with it.
Suppose our variable is of integer type, so my integer’s data type or the return type which will be there, even that will remain as an integer.
So, it will be confirmed that it can point towards only integer type variables.
In the same way, the return type of the function, it’s return type and the return type of the pointer will be the same, with this we understand that this type of function and our pointer's return type would be the same.
With this we understand that it can point to this type of function.
Can we make such a thing in which the pointer will be generalised, it won't have a specific data type, with this what will happen, if we want to point to some other thing or some other type of variable, we can do that easily.
In that situation.
The data type that we write that is void and void as we all know is nothing.
which means the void data type is applicable for everything.
In void data type, you can point integer, you can point a float and some other type of variable as well.
So, it is a pointer that has no associated data type with it.
It can hold addresses of any type and can be typecast at any time.
So here what happens? The pointer that has been made is of a void data type.
What is the benefit that we get from it? The benefit that we get is we can point to any one in a generalised way.
There is any type of variable, integer float, we can point it along with that, going ahead we can also change this, I want to just limit it for the integer.
In this way, we can also typecast the data type and that's why our void pointer is differentiated from our null pointer.
So, this was about a null pointer and about a void pointer.
We will go ahead and see a third pointer which we call a wild pointer. Now what is this thing? We have seen null and void pointers, now what exactly is this wild pointer? Here we will understand that “wild pointers are also called uninitialized pointers”.
Now you must have seen that whenever we're making the pointers, we write its data type and we put the asterisk mark, if it's pointing to the function, we put the argument list in front of it.
But you must have seen that in all these processes it is important for us to initialise, which means how? If we want to point any variable, we write the variable’s name and in front of it, we put ampersand in front of it, so that we can access its address and we assign it inside the pointer, in the same way we are initialising every pointer as we have to use it going ahead.
But if I say we are making such a pointer which we do not initialise, if we have not initialised it so what we will call it, we will call it wild pointer, we also call it as uninitialized pointer.
These uninitialized pointers are actually pointing towards any random values.
Now the values that are getting stored in them, those will be basically any random values.
This means that it will start pointing to any random value, the address is not written on it to point on a specific value.
What will happen with this, whenever we want to extract, access or print the address.
In that situation, our compiler will give us an error and it will tell us this pointer is pointing anywhere, it is wanting at any random value.
That's why this is one wild pointer.
You either initialise it or you discard it.
This kind of an error our compiler would be giving us.
How will these things work? How we will understand the wild pointer.
How will we understand null pointers and the wild pointers? These we will understand when we will use them practically.
So here in this video also we will discuss these three pointers practically. -8:50
So, we will quickly go into our text editor in our Visual Studio code and here first of all we will start our program.
So first we will see what we were doing in the program.
In this programme we will use all three pointers and see which means we will create all these three pointers; we will create them and we will bring them to use here.
Because of which we will get to know about its characteristics and properties easily.
So, we will start with our program.
Here you can see that first of all we are writing our pre-processing command, which is hash include S T D I O dot H.
What does it do? It is helping us to import the file.
Now we will go ahead and see further, int main, which means we have started the main function.
Since we have started the main which means the main function.
Now since we have started the main function, it means that we have not written any function definition or function declaration for now.
If we had to write, we would have written it before the main function.
So here directly we have started the main function because there is no need of making the functions over here, we just wanted to understand how our pointer becomes a different type of pointer at the time of its initialization or creation.
So, now we have come to our main function and we will go ahead, here first of all, as we had discussed null pointer in the same way we will be creating a null pointer over here.
So, you can see here our program in which we have made a pointer named P T R, in which the data type, we have kept it as I N T or integer.
What we have assigned it with, that is the thing to concentrate over here.
We have assigned it towards N U L L.
What exactly is it? N U L L type is an identifier, which means it is a keyword.
And what does this keyword do? We had seen null theoretically, null means that it is not pointing anywhere.
It means that this PTR pointer that we have made, inside that the address that will be stored, will also be zero.
Because it is not pointing anywhere.
This is pointing towards null.
Null means here, nothing.
If the null means nothing, we will say that the pointer is not pointing anywhere.
That is the reason, the address that is stored in it, will be zero.
How is this zero stored? That we will see here with the help of a printf statement and in the printf statement we have written, the value inside variable P T R is, ahead of it we have put a format specifier.
And here in P T R whatever value is stored, we are trying to print it.
So, this was about our null pointer, we will run it and see but before that we will also make the void pointer and see with which it will be clear that the basic difference between them, how it is visible over here.
So, we will make our void pointer here.
Now we have made the void pointer in the name of P and you can see that its data type is also V O I D.
It is a void data type and with a void data type we understand that it can point at any type of value, our compiler will not give any error.
So, this was about a void pointer.
So now you can see here we have pointed this P pointer towards null as well.
So here you can say that a void pointer can also be a null pointer.
In the same way a null pointer can also be a void pointer.
Both of them can be each other my point of pointer towards that will be one null pointer.
Along with that if the data type is void then it can also be called as a void pointer.
So, this is the basic difference between these two, we will try to visualise it.
So, this was about the null pointer and about the void pointer.
After this we will see one more pointer, which we call a wild pointer.
Now before seeing how this wild pointer works, we will complete our program and we will first execute the null and void pointers.
So here we can see that we have written one line for null pointer, there is a null pointer named PTR, which we have created over here, we have also made one void pointer which is called P and what we are doing here, we are printing the size of the Pointer.
The size of the pointer is, ahead of it we have put one format specifier and what we have done, with the help of size of function, what does the size of function do? whatever value we are passing inside it, suppose we are passing a variable or a pointer exactly how much storage space it is going to take, what is its size going to be, that prints and tells us, size of function.
So, this was about null pointer and void pointer.
So, we have closed the main function over here.
How? By writing the return zero statement and these two lines which you can see, we have commented it for now.
Which means our compiler will skip these two lines.
Why will it skip it? As we know that when we are putting this double forward slash at that time, we will convert that line into one comment and what will be that comment? That comment helps us to make our programme effective and readable.
What happens with this? We get to understand what that particular line wants to do? What we are trying to do here and what has happened here, it helps us when our program is very long.
And we forget after coding it, that what we had written in the first line or the fifth line.
So, to remember what exactly this part of code explains.
So, all these things help us when we make the comments, so these comments are helping us in this way.
So, here we have commented on these two lines.
Now we will save it and we will try to execute it.
For executing, we know that we have to use the G C C command and we have to write our file’s name over here.
As soon as we press enter our program or code will get compiled.
Now after getting it compiled, we will run it.
So, you can see here that this is a thing to concentrate on our null pointer, how it is getting printed over here and along with that how the void pointer has got printed over here.
So, you can see that first of all at the null pointer.
Here we tried to print a printf statement and the value inside the variable PTR is, ahead of it, whatever address was stored in PTR while pointing at the null that we have printed.
So, you can see ahead of it, in that line, the value inside variable PTR is equal to zero.
So, zero has got stored inside our pointer, which means it has not got any address.
Why? Because it was pointing at null means it was not pointing at anyone.
So, this was about a null pointer.
Now we will come to our void pointer.
If you see in the void pointer, we have made a void pointer with the name P, we have initialised it towards null but its data type, we have kept it void.
What happens with this? When we printed its size.
So, “the size of the pointer is” ahead of this we have written 8.
So, with this we understand that this data type is void and the void’s size is eight because of this, we can point it towards the integer, towards the float, towards the character as well.
So, this becomes very generalised, our pointer.
This was a matter of a null pointer and about void pointer.
And after this we will come to our wild pointer and we will see how this wild pointer works.
We will remove it from comments and we will save it, before that we will understand what we want to write here.
So, this PW is basically a wild pointer.
Why is it a wild pointer? We just learned what a wild pointer is, it is an uninitialized pointer.
So, you can see, first in both the pointers, we have put equal to sign, by putting assignment operators, we have tried to assign some value in front of it.
But in front of this wild pointer, we have not put any equal to sign.
Which means in PW we have not tried to store anything like this.
Because of this it has stayed uninitialized and uninitialized pointer we call as the wild pointer.
Now we will print it and see exactly what PW is pointing at.
To see where it is pointing, we will execute it and for that we will again go back to our terminal, we will again have to execute it or compile it.
We will press enter with this command and again we will press a character here.
As soon as we press enter, you can see that no statement is getting printed over here related to this wild pointer.
So, we will check here once why has this exactly happened? So here is the wild pointer which is there.
It is behaving differently.
Why? Because we have not assigned it anywhere.
So, you can see the first two statements which are there.
If we comment those, if I comment these two statements, our void and null pointers, after that if I keep only the wild pointer apart, will it execute and come here.
We will also execute this once and see, as soon as we will execute it.
You can see that nothing has got printed over here.
Why has this not come? Because the PW pointer which is there is not pointing anywhere because it has not been initialised anywhere.
Since it has not been initialised, it is not pointing anywhere, which means that there is no value that has been stored in it, that’s why, nothing is getting printed in our output and if I want to see what is the value that is stored inside it, if I want to say that I will remove the Asterix symbol from here and I will save it and I will compile it again and execute it.
So, you can see that as soon as I have compiled and executed it.
If I see that, what is the value stored inside it? Where is it pointing that we have not initialised, what is the value that was stored in it that is important to see here.
As soon as we execute and see what is the value that has got stored in it.
It stores a random value inside it.
So here you can see that it has scored 16 in itself as an address.
Whose address is it? It is nobody's address.
Because we have not initialised it, it is not pointing anywhere and that is why this condition is called a wild pointer and here the wild pointer is a mistake over here.
So, whenever you are making a pointer, you have to keep in mind that this pointer should not get converted into a wild pointer.
Because if you're making this wild pointer and you forget to assign it anywhere, then what will happen…maybe any statements might not get printed in it or it might also give an error.
So, the behaviour of our program can bring a hindrance to it.
That is why, we will try here that we should never make one wild pointer.
We should always initialise it if we don't have any variable function to initialise, we can straight away go to our null pointer.
And we can see that when we don't have to point it towards anyone, we can point it towards null.
What happens with this the danger of turning it into a wild pointer reduces and our pointer doesn't give any error.
Smoothly, all the work gets completed over here.
So, this was about our null pointer, void pointer and wild pointer.
So, here we can make the null pointer if we have to skip a void pointer and along with that, we can make a void pointer when we want to make a generalised pointer, which can point at any type of variable.
I hope you understood whatever we learned today.
So, these were different types of pointers and we also got to know what we have to point and how we have to make those pointers, which are the pointers which we should not make, which we have to skip.
After seeing all the things now comes the time to go to the next topic.
If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
Share a personalized message with your friends.