WEBVTT

00:01.520 --> 00:07.240
Pointers provide a lot of flexibility, but this flexibility comes at safety cost.

00:07.250 --> 00:13.580
So if you don't need the flexibility or receipt ability a nullptr.

00:13.710 --> 00:16.880
References are the go to reference type.

00:16.880 --> 00:21.330
So let's drive home to the point that references cannot be reseated.

00:21.350 --> 00:28.550
So here we're going to initialize an integer reference in this lecture and then we will attempt to reseat

00:28.580 --> 00:31.070
it with the new value.

00:31.610 --> 00:35.360
So as always, we have to use the include.

00:35.390 --> 00:40.730
We will use the library, CS uh, studio here and.

00:41.830 --> 00:46.930
Then we're going to create the original variable and assign to 100.

00:47.110 --> 00:56.350
And if you like, have the problem understanding this code, which as I as I always do, I will explain

00:56.350 --> 00:58.300
after when we write the code.

00:58.480 --> 01:09.160
This is ampersand here, original href here, and we're going to assign it to original original here.

01:09.250 --> 01:11.530
And then we will print that.

01:12.250 --> 01:17.310
So remember, we included this the system library.

01:17.320 --> 01:17.980
That's why.

01:18.010 --> 01:21.130
Because we need to use the printf here.

01:21.280 --> 01:22.420
So.

01:26.490 --> 01:27.150
Here.

01:27.180 --> 01:35.730
As you can see here, we do no longer have the function print F, So that's why we included this print,

01:36.150 --> 01:39.660
this studio, um, library here.

01:39.660 --> 01:41.580
So include it again.

01:43.280 --> 01:43.850
Here.

01:43.850 --> 01:47.270
And as you can see, our printf function returns.

01:47.310 --> 01:49.880
So original here?

01:50.720 --> 01:51.260
Yes.

01:52.160 --> 01:53.470
Original here.

01:53.480 --> 01:53.930
The.

01:57.190 --> 02:01.540
And then we're going to print the original value.

02:01.540 --> 02:06.010
And then let's add another print function here and reference.

02:06.870 --> 02:07.290
Here.

02:12.770 --> 02:13.400
Here.

02:15.680 --> 02:16.670
And.

02:19.460 --> 02:22.540
Original dot reference, as you can see here.

02:22.550 --> 02:25.460
And then we're going to create a new value.

02:25.880 --> 02:28.580
Named new value and assign it to 100.

02:30.490 --> 02:36.240
Integer new value is assigned to 200 and original ref.

02:36.250 --> 02:38.350
We will use this original ref here.

02:38.800 --> 02:42.850
Original ref equals new value.

02:42.940 --> 02:46.590
And then we're going to print again this here.

02:46.600 --> 02:52.540
As you can see here, we're going to firstly, we're going to print the original, then new value.

02:52.540 --> 02:56.590
And then lastly, we're going to print the reference variable here.

02:56.620 --> 02:58.780
The first is original here.

03:02.540 --> 03:03.560
We three.

03:04.990 --> 03:07.150
We're going to pass this original here.

03:09.350 --> 03:12.140
Then we're going to print the original ref.

03:17.010 --> 03:18.420
Or new value here.

03:32.350 --> 03:34.150
And lastly, we're going to print the reference.

03:35.970 --> 03:36.300
Here.

03:38.790 --> 03:39.390
Reference.

03:39.390 --> 03:40.020
So.

03:40.020 --> 03:41.100
And then we're going to.

03:41.640 --> 03:43.650
Here, let me write it.

03:43.710 --> 03:44.190
Okay.

03:44.520 --> 03:45.960
Ref Original referee.

03:46.290 --> 03:47.790
So let's run our code.

03:51.330 --> 03:53.220
And that's our output here.

03:53.220 --> 04:05.250
So now the program here initializes initializes an integer called original and 200 here, as you can

04:05.250 --> 04:05.520
see.

04:05.640 --> 04:12.510
Then it declares a reference to original called original ref here, as you can see here.

04:12.510 --> 04:21.120
So from this point on, the original ref will always refer to original here, as you can see here.

04:21.120 --> 04:28.200
So this is illustrated by printing the value of original here.

04:30.420 --> 04:33.690
And the value of refer to type original ref.

04:34.230 --> 04:37.800
So as you can see here, we got the 100 here.

04:38.010 --> 04:48.420
Then you initialize another integer called new value to 200 and then assign original to it.

04:49.230 --> 04:50.400
As you can see here.

04:50.700 --> 04:51.630
So.

04:53.060 --> 04:53.870
Here.

04:54.530 --> 05:00.530
Read it carefully that the assignment here doesn't recede.

05:00.560 --> 05:01.760
Original ref.

05:01.940 --> 05:05.510
So that is points to new value.

05:05.810 --> 05:12.320
Rather, it assigns the value of new value to the object it points to.

05:12.350 --> 05:14.280
That is the original.

05:14.300 --> 05:24.290
So the upshot is that all of these variables original original ref and new value evaluate to 100 after

05:24.290 --> 05:25.640
this code here.
