Be some use for the int pointer pointer in the last lecture which we use for dynamically allocating
it to the array.
But it was it really me well it really means a pointer to a pointer and so a pointer that points to
another point.
In other words if you call in our pointers discussion I mentioned that you couldn't modify where pointer
points to.
If you pass it to a function the original pointer will be completely unaffected.
Well if we want to change the pointer itself or the value itself then we can pass it by pointer pointer
instead.
So let's take a look at the example I have here.
So what this program really does is all it does is create a pointer.
So you put 0.06 that owns and is going to own some memory.
So you just create a new int array of a bunch of.
It's OK Max.
So in this case 10 then I will print out the length.
So currently It's 10 on the first iteration and then I will just fill the array with some values and
then print those out.
OK.
So that's all this does.
And after that I will ask the user for some more or a new link.
And if that link is greater than zero I will actually resize the array itself using this function.
So let's just run this and see what happens.
So I like this now 10.
That's what you'd expect at the start.
And then say I ran it.
Or put a new link to be 20 and it will fill the array with 20 values.
Ok so now the array is actually 20 instead of 10.
And I said you know 9 it's only 9 now.
And if I said 0 then it quits OK.
That's greater than zero.
For this to work.
And of course I do it after.
So how did this work.
Right.
Actually.
So what this does is actually changes where this points to changes the address that this points to.
So we did this using a pointer pointer
arguments.
So notice that this resize takes it by pointer a pointer and not just one pointer.
It's not it's not this it should be this way.
So and you'll notice if you when we actually use it down here we're actually passing the address of
our pointer.
OK so that's what really that means so this pointer pointer takes an address of a pointer.
So that's what this does and that's why this is how it is here.
So the resize function again it takes a point your pointer will check to see if any pointers.
No.
If it isn't then it actually deletes the memory pointed to by the original pointer so Notice I'm using
the dereference operator here because I need to get the original pointer value original pointer address.
OK that's what this says and I actually delete it.
And then here I'll actually sent the original pointer right this is the original pointer and with the
error and the dereference operator start of it and I'll actually set it to some new size.
So I actually like i actually change where the original pointer points to.
In other words.
And how much point and the length of the array that it gets.
OK so that's kind of how this works.
So notice I can't do this so I'm deleting where
I delete that dereference like it'll start it'll mess up.
So the saying pointer being freed was not allocated meaning this double pointer never had anything to
begin OK it's only the original pointer that had something or pointed to some memory.
So that's all I really want to say about these pointer pointers we will actually use them in the battleship
project but not in terms of dynamic memory of using them in a different way.
Actually in the next lecture I want to do want to go over some one more use of pointers you might find
kind of interesting.