So or at the end of this section we'll be doing some more applications of pointers and references and
feature sections.
But we just do something a bit easier for this section.
So we only have one problem and it says it right function that will swap the two values of two integers
so we could do this with either references or pointers.
So do this with references.
So let's write a function and call that swap and you have two integers as are references.
In a in parameters so this will be our function declaration.
You know I have swap like this and just right.
The main function.
So X equals do you 5.
TWI const.
Dean and call swap
x y here.
In C out it's
set value.
X is
in in
y ints.
I like this.
So you're right now nothing will change right.
So the value of x is 5 and the value of x is a value of x is 5 and value wise D.
So by the end of this it should be the opposite.
So we do that using these references.
OK so if we how how would you swap two values.
Between each other.
So going to need a temporary variable.
Let's call it Stemp.
This and we actually set it to let's say x K and so got the value of x ray these references.
And once set x to be y y this case.
Now Vout X gets the value of Y and if we want there to complete it we just say that.
Y equals to 10.
Right.
So we just set the value X to attempt to store it for later use because we're going to change X and
then the very next line so X now becomes 15.
Here are.
And then Y gets the value of temp which was 5.
In this case.
OK.
So let's run this
so value of x is 15 in value of y is 5 k.
So again we're using references.
Swap the values
so we could be doing this with pointers.
But I think I'll leave that up to you on how to do that properly.
And in the next section we're going to talk about arrays.