WEBVTT

00:01.040 --> 00:11.030
Be some use for the int pointer pointer in the last lecture which we use for dynamically allocating

00:11.280 --> 00:13.310
it to the array.

00:13.970 --> 00:21.530
But it was it really me well it really means a pointer to a pointer and so a pointer that points to

00:21.680 --> 00:22.730
another point.

00:22.730 --> 00:29.540
In other words if you call in our pointers discussion I mentioned that you couldn't modify where pointer

00:29.540 --> 00:30.170
points to.

00:30.170 --> 00:37.890
If you pass it to a function the original pointer will be completely unaffected.

00:38.380 --> 00:47.710
Well if we want to change the pointer itself or the value itself then we can pass it by pointer pointer

00:47.710 --> 00:48.240
instead.

00:48.280 --> 00:52.470
So let's take a look at the example I have here.

00:52.540 --> 01:00.230
So what this program really does is all it does is create a pointer.

01:00.430 --> 01:05.010
So you put 0.06 that owns and is going to own some memory.

01:05.080 --> 01:11.410
So you just create a new int array of a bunch of.

01:11.890 --> 01:13.250
It's OK Max.

01:13.280 --> 01:18.200
So in this case 10 then I will print out the length.

01:18.200 --> 01:24.890
So currently It's 10 on the first iteration and then I will just fill the array with some values and

01:24.890 --> 01:27.290
then print those out.

01:27.530 --> 01:28.020
OK.

01:28.060 --> 01:30.470
So that's all this does.

01:30.470 --> 01:37.960
And after that I will ask the user for some more or a new link.

01:38.270 --> 01:48.460
And if that link is greater than zero I will actually resize the array itself using this function.

01:48.470 --> 01:52.660
So let's just run this and see what happens.

01:53.600 --> 01:56.100
So I like this now 10.

01:56.150 --> 01:58.390
That's what you'd expect at the start.

01:58.400 --> 02:00.260
And then say I ran it.

02:00.260 --> 02:06.710
Or put a new link to be 20 and it will fill the array with 20 values.

02:06.760 --> 02:11.060
Ok so now the array is actually 20 instead of 10.

02:12.040 --> 02:18.190
And I said you know 9 it's only 9 now.

02:18.770 --> 02:23.270
And if I said 0 then it quits OK.

02:23.530 --> 02:24.790
That's greater than zero.

02:24.830 --> 02:26.130
For this to work.

02:26.420 --> 02:28.840
And of course I do it after.

02:28.850 --> 02:30.980
So how did this work.

02:30.980 --> 02:31.450
Right.

02:31.700 --> 02:32.370
Actually.

02:32.450 --> 02:39.740
So what this does is actually changes where this points to changes the address that this points to.

02:39.800 --> 02:43.040
So we did this using a pointer pointer

02:45.280 --> 02:46.320
arguments.

02:46.480 --> 02:53.210
So notice that this resize takes it by pointer a pointer and not just one pointer.

02:53.290 --> 02:56.440
It's not it's not this it should be this way.

02:56.500 --> 03:04.870
So and you'll notice if you when we actually use it down here we're actually passing the address of

03:05.050 --> 03:06.730
our pointer.

03:07.050 --> 03:14.380
OK so that's what really that means so this pointer pointer takes an address of a pointer.

03:14.440 --> 03:19.080
So that's what this does and that's why this is how it is here.

03:21.140 --> 03:28.970
So the resize function again it takes a point your pointer will check to see if any pointers.

03:28.980 --> 03:29.560
No.

03:30.170 --> 03:40.070
If it isn't then it actually deletes the memory pointed to by the original pointer so Notice I'm using

03:40.070 --> 03:50.530
the dereference operator here because I need to get the original pointer value original pointer address.

03:50.570 --> 03:54.630
OK that's what this says and I actually delete it.

03:55.070 --> 04:02.700
And then here I'll actually sent the original pointer right this is the original pointer and with the

04:02.710 --> 04:11.040
error and the dereference operator start of it and I'll actually set it to some new size.

04:11.630 --> 04:17.790
So I actually like i actually change where the original pointer points to.

04:17.790 --> 04:18.620
In other words.

04:18.660 --> 04:23.870
And how much point and the length of the array that it gets.

04:24.090 --> 04:29.050
OK so that's kind of how this works.

04:29.070 --> 04:34.800
So notice I can't do this so I'm deleting where

04:37.960 --> 04:42.160
I delete that dereference like it'll start it'll mess up.

04:42.170 --> 04:52.030
So the saying pointer being freed was not allocated meaning this double pointer never had anything to

04:52.030 --> 05:02.270
begin OK it's only the original pointer that had something or pointed to some memory.

05:02.440 --> 05:10.560
So that's all I really want to say about these pointer pointers we will actually use them in the battleship

05:10.560 --> 05:15.900
project but not in terms of dynamic memory of using them in a different way.

05:15.900 --> 05:26.470
Actually in the next lecture I want to do want to go over some one more use of pointers you might find

05:26.530 --> 05:27.310
kind of interesting.
