WEBVTT

00:00.360 --> 00:06.560
So or at the end of this section we'll be doing some more applications of pointers and references and

00:06.560 --> 00:07.960
feature sections.

00:08.220 --> 00:14.140
But we just do something a bit easier for this section.

00:14.140 --> 00:21.870
So we only have one problem and it says it right function that will swap the two values of two integers

00:22.560 --> 00:27.670
so we could do this with either references or pointers.

00:27.670 --> 00:31.810
So do this with references.

00:32.400 --> 00:44.800
So let's write a function and call that swap and you have two integers as are references.

00:46.810 --> 00:56.620
In a in parameters so this will be our function declaration.

00:57.540 --> 01:03.080
You know I have swap like this and just right.

01:03.120 --> 01:04.630
The main function.

01:04.640 --> 01:07.860
So X equals do you 5.

01:08.470 --> 01:09.540
TWI const.

01:09.660 --> 01:12.350
Dean and call swap

01:16.340 --> 01:18.300
x y here.

01:20.940 --> 01:23.540
In C out it's

01:27.320 --> 01:29.600
set value.

01:32.190 --> 01:33.840
X is

01:39.650 --> 01:40.650
in in

01:47.080 --> 01:50.230
y ints.

01:50.820 --> 01:54.310
I like this.

01:54.780 --> 01:58.130
So you're right now nothing will change right.

01:58.200 --> 02:05.520
So the value of x is 5 and the value of x is a value of x is 5 and value wise D.

02:05.580 --> 02:08.880
So by the end of this it should be the opposite.

02:08.880 --> 02:12.910
So we do that using these references.

02:12.920 --> 02:20.970
OK so if we how how would you swap two values.

02:22.070 --> 02:23.420
Between each other.

02:23.560 --> 02:28.220
So going to need a temporary variable.

02:28.280 --> 02:30.250
Let's call it Stemp.

02:30.500 --> 02:42.170
This and we actually set it to let's say x K and so got the value of x ray these references.

02:44.920 --> 02:52.640
And once set x to be y y this case.

02:52.670 --> 03:02.150
Now Vout X gets the value of Y and if we want there to complete it we just say that.

03:02.180 --> 03:03.740
Y equals to 10.

03:04.130 --> 03:04.840
Right.

03:05.210 --> 03:13.470
So we just set the value X to attempt to store it for later use because we're going to change X and

03:13.470 --> 03:18.440
then the very next line so X now becomes 15.

03:18.440 --> 03:19.500
Here are.

03:20.130 --> 03:24.500
And then Y gets the value of temp which was 5.

03:24.510 --> 03:26.050
In this case.

03:26.160 --> 03:26.710
OK.

03:26.850 --> 03:28.520
So let's run this

03:31.010 --> 03:36.720
so value of x is 15 in value of y is 5 k.

03:37.190 --> 03:39.560
So again we're using references.

03:39.560 --> 03:41.100
Swap the values

03:46.300 --> 03:48.310
so we could be doing this with pointers.

03:48.320 --> 03:52.770
But I think I'll leave that up to you on how to do that properly.

03:53.640 --> 03:57.570
And in the next section we're going to talk about arrays.
