In this lecture you will learn about the references in C plus plus.
References are safer, more convenient versions of pointers.
You declare references with this ampersand declaration here um, appended to the type name.
So references cannot be assigned to null and they cannot be reseated or resigned.
So these characteristics eliminate some bugs endemic to pointers.
So the syntax for dealing in references is much cleaner than for pointers.
So rather than using the member of Pointer and the reference operators, you use references exactly
as if they are of the pointer to type.
So.
Now I want to create some, uh, firstly, we going to create the ad here outside of the main function,
of course we're going to create the void ad year, ad year.
So we will fill this function after creating our struct, which we're going to create a struct here
named the.
World clock.
World clock here.
Or let's make name it for the year here.
World year.
And in this racket, we're going to have the integer type integer variable named year here.
And we're going to use the getter and setter methods to assign this year something.
First, let's assign use getter method here integer.
We will make made.
We made this integer because the getter method, as you know, returns something on it.
So in this case, we're going to return the integer number.
Uh, integer.
Get here.
Here.
And return.
Return here.
Here.
And we're going to use the setter method as well.
The setter method can be just, uh, void in this case.
Uh, set.
Set here and integer.
The temporary year here.
And.
Year equals to year.
And then we're going to let's create an.
This function here.
Here.
So firstly.
We're going to this add parameter will get the struct type name the world year and as a parameter.
So world year this ampersand here and uh, for example my.
For X year here.
And then.
Uh, x here.
X here.
Dot set here.
Here.
And x here.
That.
Get here plus one.
That's because we're going to increment our the year.
Uh, by one, whenever we execute this function here.
And let's come to the main function here.
Uh, here.
My world.
World.
Here.
World year.
Um, Earth, for example.
My earth here.
We're going to print something on the screen.
Screen here.
In this case, we're going to print the variable named year.
The year is the year is decimal.
I will explain all of these codes one by one later after we have done this project here in this lecture.
So.
Clock Dot, Get here.
Clock that actually not clock my earth, that gate here.
And after that we're going to call the adhere function and pass my earth as a parameter.
And after that we will print the print this again.
Here.
And let's run our program now.
As you can see here, this returned first to zero and then one which this means our variable incremented
by one.
So.
Uh, so for example, if I want to just return the 2023, in this case, I have to assign my Earth dot
set year 2020 22 and it will increment the year two by one.
So now I want to talk about these codes one by one, what we did in the technical manner of this.
So you the firstly, you declare the world year argument as here.
As a reference using the ampersand.
Rather than asterisk here, as you can see here.
Then within a add year, you use the X year as if it were of the type world year.
So there's no need to use a clumsy dereference and pointer to reference operators.
First, you print the value as a value of year here.
And the next, uh, at the call site, you pass the, uh, my Earth object directly into.
Here.
Add the year and there's no need to take its address.
Finally, you print the value of year again to illustrate that it has incremented.
As you can see here.