1 00:00:00,560 --> 00:00:06,800 You can also create a race of objects in dynamic memory using the new operator. 2 00:00:06,800 --> 00:00:13,340 So you did this by providing the number of items you want to create in a pair of square braces here. 3 00:00:13,400 --> 00:00:22,250 So this code here, that driver light here P new integer two and P zero. 4 00:00:23,600 --> 00:00:28,610 Zero here one and this pointer here. 5 00:00:29,300 --> 00:00:30,890 P plus one. 6 00:00:31,280 --> 00:00:33,560 And here, two. 7 00:00:34,460 --> 00:00:38,840 And then we're going to create a for loop here integer E zero. 8 00:00:39,350 --> 00:00:41,180 While E less than. 9 00:00:42,290 --> 00:00:42,880 Two. 10 00:00:43,580 --> 00:00:46,310 Increment E by one. 11 00:00:46,610 --> 00:00:54,620 And then we're going to print the print the P variable here, P here. 12 00:00:56,070 --> 00:00:56,790 In line. 13 00:00:58,130 --> 00:01:02,120 And after this for loop, we're going to delete the P. 14 00:01:03,770 --> 00:01:03,990 Yeah. 15 00:01:06,630 --> 00:01:12,120 So the operator here returns a pointer to the time allocated. 16 00:01:12,120 --> 00:01:17,610 So and you use the pointer arithmetic or array indexing to access the memory. 17 00:01:17,640 --> 00:01:25,080 You cannot initialize the memory in the new statement, so you have to do that after creating the buffer 18 00:01:25,080 --> 00:01:25,560 here. 19 00:01:25,740 --> 00:01:32,490 So when you use a new to create a buffer for more than one object, you must use the appropriate version 20 00:01:32,490 --> 00:01:34,820 of the delete operator. 21 00:01:34,830 --> 00:01:43,410 And the caller braces is used to indicate that the more than one item is deleted and the destructor 22 00:01:43,410 --> 00:01:45,930 for each object will be called. 23 00:01:45,930 --> 00:01:52,500 So it's it's important that you always use the right version of delete appropriate to the version of 24 00:01:52,500 --> 00:01:56,430 new here used to create the pointers here. 25 00:01:56,550 --> 00:02:03,990 So custom types can define their own operator, the new operator and the late operator for individual 26 00:02:03,990 --> 00:02:04,440 objects. 27 00:02:04,440 --> 00:02:09,390 So as well as the operator, new collaborators here and operator. 28 00:02:09,390 --> 00:02:19,410 The delete caller is here for array of objects here, so the custom type order can use these to use 29 00:02:19,410 --> 00:02:24,000 custom memory allocation schemes for their objects. 30 00:02:26,150 --> 00:02:29,210 And here, if we get the failed. 31 00:02:30,180 --> 00:02:38,670 When you're doing this, if the new operator cannot allocate the memory and for an object, it will 32 00:02:38,670 --> 00:02:43,170 throw the STD std bad. 33 00:02:43,350 --> 00:02:52,620 I look about all the exception and the point pointer return will have the new TR here, so exceptions 34 00:02:52,620 --> 00:02:55,920 are covered in next lecture, next lectures. 35 00:02:55,920 --> 00:02:56,040 So.