Pointers provide a lot of flexibility, but this flexibility comes at safety cost.
So if you don't need the flexibility or receipt ability a nullptr.
References are the go to reference type.
So let's drive home to the point that references cannot be reseated.
So here we're going to initialize an integer reference in this lecture and then we will attempt to reseat
it with the new value.
So as always, we have to use the include.
We will use the library, CS uh, studio here and.
Then we're going to create the original variable and assign to 100.
And if you like, have the problem understanding this code, which as I as I always do, I will explain
after when we write the code.
This is ampersand here, original href here, and we're going to assign it to original original here.
And then we will print that.
So remember, we included this the system library.
That's why.
Because we need to use the printf here.
So.
Here.
As you can see here, we do no longer have the function print F, So that's why we included this print,
this studio, um, library here.
So include it again.
Here.
And as you can see, our printf function returns.
So original here?
Yes.
Original here.
The.
And then we're going to print the original value.
And then let's add another print function here and reference.
Here.
And.
Original dot reference, as you can see here.
And then we're going to create a new value.
Named new value and assign it to 100.
Integer new value is assigned to 200 and original ref.
We will use this original ref here.
Original ref equals new value.
And then we're going to print again this here.
As you can see here, we're going to firstly, we're going to print the original, then new value.
And then lastly, we're going to print the reference variable here.
The first is original here.
We three.
We're going to pass this original here.
Then we're going to print the original ref.
Or new value here.
And lastly, we're going to print the reference.
Here.
Reference.
So.
And then we're going to.
Here, let me write it.
Okay.
Ref Original referee.
So let's run our code.
And that's our output here.
So now the program here initializes initializes an integer called original and 200 here, as you can
see.
Then it declares a reference to original called original ref here, as you can see here.
So from this point on, the original ref will always refer to original here, as you can see here.
So this is illustrated by printing the value of original here.
And the value of refer to type original ref.
So as you can see here, we got the 100 here.
Then you initialize another integer called new value to 200 and then assign original to it.
As you can see here.
So.
Here.
Read it carefully that the assignment here doesn't recede.
Original ref.
So that is points to new value.
Rather, it assigns the value of new value to the object it points to.
That is the original.
So the upshot is that all of these variables original original ref and new value evaluate to 100 after
this code here.