The reference operator that the reference operator is a unit operator that accesses the object to which
a pointer refers.
Here, let me take the note here.
The reference.
Operator here.
So this is the inverse operation of the address of operator like the address of operator.
System programmers used the reference operator very often.
So many operating system APIs will return pointers and if you want the access to refer to Albrecht,
you will use the reference operator here.
So unfortunately that the reference operator can cause a lot of notation based confusion for beginners
because the reference operator, the Pointer Declaration and the multiple action all use asterisk.
So remember that you append an asterisk to the.
End of the pointer to type objects type to declare a pointer.
So however you prepend the reference operator and asterisk to pointer.
So like this, for example, my my variable address here.
So.
After excising an object by pretending that the reference operator to a pointer, you can treat a result
like any other object of the pointer to type.
So for example, because the my variable is an integer, you can write the value into my variable using
the my variable address pointer here.
So the syntax is like that, my variable address and here 995.
And as you can see here, we've brought this variable by using a pointer, but we used the reference
operator.
So let's print our variable name.
My variable.
Well here.
Well, let's print out a variable value and decimal and.
Here.
My vegetable.
And run.
And as you can see here, we assigned.
This variable address using variable address with the reference operator.
So because that the reference pointer that is my variable address appears on the left side of the equal
sign you are writing to the address.
Where gets here?
My variable address is stored, so if the reference pointers appears anywhere except the left side of
an equal sign, you are reading from the address.
So to retrieve the integer pointer to by the my variable address here, you can tack on the reference
operator.
For instance, this code here will print a value stored in the my variable here.
So here.
The simple.
Integer or just an integer here.
The.
And my variable address.
Here and this will take from it.
Here.
Right.
And as you can see here, this cutter turned the same number here.
So.
Q I'm.
I want to get some code.
Some example code that we will make it happen to show how this the reference and address of operators
work in depth in C++.
So let's firstly here we will create the.
Integer my variable here and assign it to zero.
Or let's change a name here.
My car.
Assign it to zero.
Or let's change to my age here.
It was be more appropriate for an integer.
So integer.
This the reference pointer here, as you can see here.
Integer.
My age address.
Here.
So I want to mention that it doesn't matter if you write the this asterisk operator here or just after
the here, because actually it's just the your you can write the both sides but it have to between integer
and the variable name in C++ here.
So I will write in this time I will write here my age address address here and my age.
I will explain all of this codes later.
Printf.
Here.
Value at my age.
Address.
Here and we will print that a new line here.
Will use that.
We will use the assets, the reference operator.
And as you know, this is the address of operator.
We will use both of them in this example code my age address and then print F again.
My age my age address here.
As you know, the format specified for pointer is P and the new line.
Here.
We will write my age address here just and without the reference of other referencing or without the
referencing or others of operator, because this is my address itself is just a pointer type integer
pointer type here.
So then we will assign, we will use the asterisk here and assign it to nine for example, 1019 nine
here.
Ten 129 nine.
And then.
And printf.
Here.
Value.
Well, you add my, uh, my age address here.
Decimal.
As you know, this is an integer format format specified for integer.
And we will use the asterisk, the reference operator, and my my age address.
My age.
As you can see, we can use the my age by itself because in direction requires pointer operant here.
And that's why we will use you.
We will use the integer pointer here and then print F.
Lastly.
Here's my bar address or my age Address.
Sorry.
My age address.
Here.
Pointer type.
Yeah.
Here.
My age address without any operators.
And let's run our code.
And I will explain all of this in this lecture.
So.
First you initialize the my age to zero.
Then you initialize to the pointer here to the pointer.
My age address to the address of my H here.
So next you print the.
Integer pointed to by address here.
As you can see, we use the asterisk operator here, the reference operator, and we will we will print
the value of the my age address here.
So then we write the value ten, nine, nine, 1009 and nine into the memory, pointed to my age address
and then print the pointed to value here as you can see here and the address again.
So then as you can see here, we this is the pointer to type and this is the address here.
So and as you can see here, firstly my age addresses was equal to zero.
And then.
Uh, here.
The.
Address was same to and after the initialization here or changing the address to changing the variable
of my edge variable to another var here and value here.
And as you can see, we got the same addresses but different values.