In this lecture, you will learn about the references in C++.
References are safer, more convenient versions of pointers.
You declare references with this ampersand declaration here appended to the type name.
So references cannot be assigned to NULL and they cannot be revisited 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 the sum.
Firstly, we're 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 f they're creating our struct, which we're going to create a struct here
named the.
Wall clock.
World clock here.
Or let's make name it for the year.
Year.
World year.
And in this struct, 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 assigned use this getter method here integer.
We will make them 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.
Integer.
Get here.
Here.
And return.
Return.
Here.
And we're going to use this setter method as well.
This other method can be just a void in this case.
Uh, set.
Set for a year and integer.
The temporary.
Yea.
And.
Years equals to fear.
And then we're going to let's create an.
This function here.
Here.
So firstly.
We're going to this adhere parameter will get the struct type name the world and the as a parameter.
So world here, this ampersand here.
And uh, for example, my.
For x.
Yea.
And then.
Uh ix yea x yea.
That said, here, here and here that get here plus one.
That's because we're going to increment our the year.
By one whenever we execute this function here and let's come to the main function here.
Here, my world.
World Year here.
World Year.
World Year Earth, for example.
My Earth here.
We're going to print something on a string screen here.
In this case, we're going to print the variable name.
The year.
The year is the year is decimal.
I will explain all of this course one by one later after we done this project here in this lecture.
So.
Clock that gate here.
Clock that actually not clock my earth that get here.
And after that we're going to call the ED 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 returns first to zero and then one, which this means our variable incremented
by one.
So.
So, for example, if I want to just return the 2028 tree, in this case, I have to assign my Earth
date set year 20 2022 and it will increment the year to buy one.
So now I want to talk about this course one by one.
What we did in the technical manner of this.
So you firstly you declare the world year argument as here.
As a reference using the ampersand.
Rather than acid is clear, as you can see here.
Then within the ad year you use the x year as if it were of the type world year.
So there is no need to use a clumsy the reference and point or to a reference operators.
First you print the value as the value of year here.
And the next.
At the concert you passed my Earth object directly into.
Here.
Add the.
And there's no need to take its address.
Finally, you print the value of year again to illustrate that it has incremented.
And as you can see here.