So we saw before we could pass in values to functions so you could have something like this function
and say it takes in an integer right.
And if you define an integer mean say call it with the function pass in the X and say it's it's print.
Ouch.
Value x.
It's here it's this.
And we define the function down here.
Say we can actually change the value right.
If we wanted to know why it's us and we're in this C nothing surprising the value of y is gain and the
value of x is 5.
So we see that if we pass in the value of x into this function get change that value but it wouldn't
change the original collar's variable at all.
Right.
So we're changing it to 15.
But that doesn't affect X at all.
And this is called pass by value.
So we're just kind of copying the value into this function and just giving it in this case 5 say but
actually have pointers here as are our parameters.
Change it to be a pointer.
Why do you take the address of X right.
Because we have to pass in the address.
This is remember that pointers taken addresses right.
That's their values.
And if we change all this what do you think the outcome should be.
Let's try and see as your reference
so you can see that the value of y is 15 and the value of x is 15.
So what's going on.
Well since we're passing the address of x K and again we're passing the address here we're changing
x.
This changes X because now y points to x.
So why can change x's value right.
So that's why it's changing here.
So this is called passed by reference.
So we're passing a reference to X's address here.
OK.
So this is one of the powerful features of pointers.
This is why we use them so much as this is one of the good reasons for it.
We can also do this with references to change this reference this.
Now we don't need this right or that this k should see the same thing.
Q Why is 15 in the value of X mean.
Just so you totally believe me it's rere and this was a different value.
Now it's 20 k so I'll often use references as per function parameters.
Actually that's one of the primary uses I think of references is do you have it as a parameter.
Often not for simple values like integers because usually you just want it to be just the value.
So that's fine but later on you'll see that we really want to use references for a very specific reason.
And I'll get into that in this in the future section.