WEBVTT

00:00.830 --> 00:05.690
In this lecture you will learn about the references in C plus plus.

00:05.720 --> 00:11.000
References are safer, more convenient versions of pointers.

00:11.030 --> 00:19.730
You declare references with this ampersand declaration here um, appended to the type name.

00:19.730 --> 00:26.380
So references cannot be assigned to null and they cannot be reseated or resigned.

00:26.390 --> 00:31.430
So these characteristics eliminate some bugs endemic to pointers.

00:31.430 --> 00:36.680
So the syntax for dealing in references is much cleaner than for pointers.

00:36.680 --> 00:44.330
So rather than using the member of Pointer and the reference operators, you use references exactly

00:44.330 --> 00:47.600
as if they are of the pointer to type.

00:47.600 --> 00:48.290
So.

00:49.040 --> 00:56.360
Now I want to create some, uh, firstly, we going to create the ad here outside of the main function,

00:56.390 --> 01:02.720
of course we're going to create the void ad year, ad year.

01:02.720 --> 01:11.420
So we will fill this function after creating our struct, which we're going to create a struct here

01:11.420 --> 01:12.590
named the.

01:13.650 --> 01:14.790
World clock.

01:14.820 --> 01:16.980
World clock here.

01:18.210 --> 01:23.220
Or let's make name it for the year here.

01:23.280 --> 01:24.540
World year.

01:25.290 --> 01:33.510
And in this racket, we're going to have the integer type integer variable named year here.

01:33.660 --> 01:39.420
And we're going to use the getter and setter methods to assign this year something.

01:40.290 --> 01:46.170
First, let's assign use getter method here integer.

01:47.540 --> 01:48.650
We will make made.

01:48.740 --> 01:55.430
We made this integer because the getter method, as you know, returns something on it.

01:55.430 --> 01:58.250
So in this case, we're going to return the integer number.

01:59.250 --> 02:00.210
Uh, integer.

02:00.240 --> 02:01.230
Get here.

02:01.260 --> 02:02.130
Here.

02:02.250 --> 02:05.460
And return.

02:05.460 --> 02:07.850
Return here.

02:08.110 --> 02:08.830
Here.

02:09.480 --> 02:12.590
And we're going to use the setter method as well.

02:12.600 --> 02:18.120
The setter method can be just, uh, void in this case.

02:18.870 --> 02:20.370
Uh, set.

02:20.880 --> 02:24.840
Set here and integer.

02:26.590 --> 02:29.080
The temporary year here.

02:30.140 --> 02:30.950
And.

02:32.820 --> 02:36.600
Year equals to year.

02:42.300 --> 02:45.030
And then we're going to let's create an.

02:46.010 --> 02:47.270
This function here.

02:50.300 --> 02:50.960
Here.

02:51.350 --> 02:53.060
So firstly.

02:54.250 --> 03:03.550
We're going to this add parameter will get the struct type name the world year and as a parameter.

03:03.640 --> 03:12.310
So world year this ampersand here and uh, for example my.

03:13.030 --> 03:15.400
For X year here.

03:16.500 --> 03:17.490
And then.

03:19.140 --> 03:20.550
Uh, x here.

03:20.790 --> 03:21.530
X here.

03:21.540 --> 03:23.100
Dot set here.

03:23.750 --> 03:24.190
Here.

03:24.240 --> 03:24.960
And x here.

03:24.960 --> 03:25.830
That.

03:25.830 --> 03:28.710
Get here plus one.

03:29.190 --> 03:33.450
That's because we're going to increment our the year.

03:34.390 --> 03:39.850
Uh, by one, whenever we execute this function here.

03:39.850 --> 03:43.030
And let's come to the main function here.

03:43.460 --> 03:44.440
Uh, here.

03:44.500 --> 03:46.030
My world.

03:46.420 --> 03:46.990
World.

03:47.020 --> 03:47.310
Here.

03:47.320 --> 03:47.650
Here.

03:47.770 --> 03:49.120
World year.

03:49.240 --> 03:50.800
World year.

03:51.490 --> 03:53.680
Um, Earth, for example.

03:53.680 --> 03:56.710
My earth here.

03:57.670 --> 04:00.230
We're going to print something on the screen.

04:00.440 --> 04:01.750
Screen here.

04:01.750 --> 04:06.310
In this case, we're going to print the variable named year.

04:06.610 --> 04:11.430
The year is the year is decimal.

04:11.440 --> 04:19.210
I will explain all of these codes one by one later after we have done this project here in this lecture.

04:20.350 --> 04:21.070
So.

04:21.790 --> 04:23.680
Clock Dot, Get here.

04:24.810 --> 04:29.700
Clock that actually not clock my earth, that gate here.

04:30.330 --> 04:39.450
And after that we're going to call the adhere function and pass my earth as a parameter.

04:40.180 --> 04:45.730
And after that we will print the print this again.

04:47.710 --> 04:48.340
Here.

04:51.330 --> 04:54.120
And let's run our program now.

04:54.780 --> 05:01.710
As you can see here, this returned first to zero and then one which this means our variable incremented

05:01.710 --> 05:02.450
by one.

05:02.460 --> 05:03.630
So.

05:04.670 --> 05:15.740
Uh, so for example, if I want to just return the 2023, in this case, I have to assign my Earth dot

05:15.800 --> 05:25.310
set year 2020 22 and it will increment the year two by one.

05:25.310 --> 05:32.870
So now I want to talk about these codes one by one, what we did in the technical manner of this.

05:32.870 --> 05:38.630
So you the firstly, you declare the world year argument as here.

05:39.690 --> 05:43.320
As a reference using the ampersand.

05:44.060 --> 05:47.240
Rather than asterisk here, as you can see here.

05:47.270 --> 05:56.320
Then within a add year, you use the X year as if it were of the type world year.

05:56.330 --> 06:01.310
So there's no need to use a clumsy dereference and pointer to reference operators.

06:01.520 --> 06:06.380
First, you print the value as a value of year here.

06:08.200 --> 06:16.240
And the next, uh, at the call site, you pass the, uh, my Earth object directly into.

06:17.290 --> 06:18.130
Here.

06:18.160 --> 06:22.510
Add the year and there's no need to take its address.

06:22.540 --> 06:30.310
Finally, you print the value of year again to illustrate that it has incremented.

06:32.170 --> 06:33.490
As you can see here.
