You can create more than just one variable using new he can create an array as well.
Let's see how you do it.
Say we had it's pointer.
This and we say new inch in the square brackets and the number of are the length of the array.
OK here using those array brackets again.
And in those brackets we're creating 10 new integers in a contiguous array so the 10 doesn't have to
be a constant or literal value.
It can be any integer created by any means.
So could have something say a length and you actually get it from the user say so please.
Like
get the link.
This and we use it here.
K so it doesn't have to be a constant value could be any integer here.
And this is why dynamic memory is so flexible it can create how many you want using this new keyword
and this is really the reason why pointers kind of act like arrays because it needs to be able to have
the ability to access all of those memory elements that it points to.
So initially this line will point to the very first memory address cancer points it kind of ahead of
the memory but we can use this like any other normal array that we could access through a pointer.
So it's an example.
It's just set the array
to say so.
And just like any other one like this it would set it to I'm plus one let's say.
And we actually just put it all over
plus to say in each here.
It's
OK so if we run this inter length let's say 20 and it prints out 20.
OK.
All 20 of these out as they see the indices go from zero to 19.
Right.
It's like a normal array.
OK.
So once you're done with that memory we should delete it like you said last time.
So instead of just saying delete pointer like we had four we actually have to say delete array pointer
OK.
Pointer here.
OK.
So when you make a new array like we do up here after you delete it using this kind of array delete
array syntax.
So we can just say delete in point int pointer like this.
Because that would only delete the very first memory address.
OK.
Which is wrong so you have to use the array delete if you if you knew that with the array new.
OK.
So in the next lecture I want to go over some best practices for using dynamic memory.