Hello and welcome to the 45th tutorial in the c++ programming series. And in this part we'll be looking at pointers. And pointer is just a variable whose value is the address of a new variable. So soar like references, it points to a normal variable. So you can make changes to a null variable via a different variable name. So you can pass this into function then you can affect the original values, like any variable or constant, you must actually declare a pointer before you can use it plus also you need to use the new keyword to dynamically allocate memory on my referencing resource anything like that itself.
So let's go ahead and open up our project. I will show you how pointers actually work. pointers is something you're definitely gonna want to get your head around. It is quite difficult to fully understanding, but it's really powerful and you'll be using a lot more Like, I was gonna create a variable. And to do a pointer you do is asterik done the name of view your variables in this case we'll put it in you do equals new, the new keyword allocates memory. And then you put well the type of data itself in open brackets semi colon, and then to assign a value to you don't employ equal wherever you asked to record because that gets the actual value or where the value is stored as it is just the memory address, equals assign a value 10 and printed as the same as while you do past record, not ice.
Mastery and oneness, you got a value. But let's show you what if we take off the big one if we look basically a memory address, maybe you do want to mess around or Work with memory address. But again, this is this is a very advanced topic. And you should be aware of how it can work before trying to mess around with the memory breath. Let's create a new variable. This time it will just be a regular variable so an assignment only 22 it won't do is do it.
So the memory address of it points to you. We named it to you. Now if we run this, we get the value 20 is pointing to you and if we make any changes to it, so you know we'll do it after we do after April 14. And then if we were to print out you it is the value 40 because when it doesn't have its own value You'd be points to a no other variable in this instance, my thinking was the main difference between a reference and a point of reference in what we covered in the previous part of the series. Well, you cannot have no references must always be able to assume that reference is connected to basically legitimate area of stories whereas, pointer you can have no pointer, obviously further be trying Be wary of null pointer they can cause error if you want some more information you can contact us or just briefly initial yes because the more information plus once a reference is initialized to an object it cannot be chained to refer to another object pointed can be pointed to another object at any given time.
A reference must be initialized when it is created pointers well can be initialized that anytime that's it for pointers here any questions feel free to message us or support us on our system Dakota UK. The email will be in the description in the description you can comment on this video or just directly comment or direct message On YouTube sorry. All the recording for source code will also be in the description. And as usual fine fortune and appeal. Nice day.