You can also create arrays of objects in dynamic memory using the new operator.
So you do this by providing the number of items you want to create in a pair of square braces here.
So this code here that I will write here.
P new integer two and P zero.
Zero here one and this pointer here.
P plus one.
And here to.
And then we're going to create a for loop here.
Integer E zero while e less than.
To increment E by one.
And then we're going to print the print, the p e variable here.
P here.
Line.
And after this for loop, we're going to delete the P.
Here.
So the operator here returns a pointer to the type allocated.
So and you use the pointer arithmetic or array indexing to access the memory.
You cannot initialize the memory in the new statement.
So you have to do that after creating the buffer here.
So when you use a new to create a buffer for more than one object, you must use the appropriate version
of the delete operator.
And the curly braces is used to indicate that the more than one item is deleted and the destructor for
each object will be called.
So it's it's important that you always use the right version of delete appropriate to the version of
new here.
Used to create the pointers here so custom types can define their own operator.
The new operator and the delete operator for individual objects.
So as well as the operator.
New curly braces here and operator that delete curly braces here, uh, for array of objects here.
So the custom type order can use these to use custom memory allocation schemes for their objects.
And here if we get a failed.
When you're doing this.
If the new operator cannot allocate the memory and for an object, it will throw the STD.
STD but outlook bad exception and the pointer returned will have the nullptr here.
So exceptions are covered in next lecture.
Next lectures.
So.