WEBVTT 00:00.950 --> 00:01.790 Welcome back. 00:02.420 --> 00:06.500 In the last lecture, you have learned everything about how to compare a race. 00:07.130 --> 00:12.620 Now in this lecture, I'm going to talk about what happens and then you assign an error to another area. 00:13.310 --> 00:14.150 Let's get started. 00:15.030 --> 00:21.810 I believe you remember Hipster's book collection from the previous lectures, now let's say you want 00:21.810 --> 00:23.670 to create the same bookcase. 00:24.180 --> 00:26.910 To do that, you can assign it to another variable. 00:27.570 --> 00:31.320 And when you do so, God creates a new bookcase. 00:32.550 --> 00:38.820 And all the elements inside of the original bookcase are copied into the new bookcase. 00:40.290 --> 00:43.370 Let me show you this in the court to understand it better. 00:44.310 --> 00:51.300 Here is the computer memory again, this time each memory represents eight bytes because the error that 00:51.300 --> 00:53.030 I'm going to create is an entry. 00:53.240 --> 00:59.250 OK, now I'm going to declare an error variable to store the capacity of the bookcase, such as this 00:59.250 --> 00:59.440 one. 00:59.820 --> 01:02.290 This creates a new era in computer memory. 01:03.120 --> 01:08.040 Then I'm going to put this blue area into a new variable named Red like this. 01:08.200 --> 01:11.570 As you can see, this is just a simple variable assignment. 01:12.150 --> 01:20.220 So when I do so go allocates a new memory space for twenty four bytes like this is because each area 01:20.220 --> 01:23.040 elements, the size is eight bytes here. 01:23.760 --> 01:28.170 The size of the allocated memory depends on the size of the element type. 01:28.680 --> 01:34.170 OK, so you assign an error to a variable or parse it to a function. 01:34.440 --> 01:40.230 Go copy's all the elements from the original array to the new one, one element at a time. 01:40.500 --> 01:47.010 It's because an array value contains all of its elements in a single array value. 01:47.250 --> 01:49.280 Think about this operation for a second. 01:49.920 --> 01:53.730 Let's say you have an array that contains one million elements. 01:54.270 --> 01:58.600 You may realize that this copying operation can be very inefficient. 01:59.010 --> 02:01.950 However, for smaller arrays, this won't be an issue. 02:02.760 --> 02:07.670 OK, now I'm going to show you that these two arrays are actually two different areas. 02:08.070 --> 02:10.710 I mean, they are equal, but they are different. 02:10.950 --> 02:14.910 It's because they are in different locations in the computer memory. 02:15.240 --> 02:21.660 Now, I'm going to assign 10 to the first element of the blue array is updates the first element like 02:21.660 --> 02:22.020 this. 02:26.250 --> 02:29.760 Did you notice that the red area is still the same? 02:30.980 --> 02:38.480 This is because it's a new era, Gore has allocated it in another memory location, they are separate, 02:38.480 --> 02:43.880 different eras, changing one of them won't be reflected in the new one. 02:44.660 --> 02:46.460 Let me show you one more example. 02:47.310 --> 02:52.520 Now, I'm going to create the reader from scratch with a different type this time like this. 02:53.730 --> 02:55.710 And interact with two elements. 02:56.250 --> 03:00.180 Now I'm going to assign the blue array to the red array like this. 03:01.660 --> 03:03.600 What do you think it is going to work? 03:05.510 --> 03:09.230 Nope, it doesn't work is because these areas have different types. 03:10.010 --> 03:15.370 So in summary, you can only assign race with identical types, OK? 03:16.670 --> 03:19.670 Let me show you a few examples in coding, Ed. 03:20.590 --> 03:26.470 Hipsters Love Bookstore has released three books last year, let's first create a three elements Trinko 03:26.650 --> 03:27.250 like this. 03:32.900 --> 03:34.460 Now, let's print the books. 03:39.290 --> 03:40.540 OK, let me run it. 03:41.430 --> 03:42.990 All right, so far, so good. 03:43.740 --> 03:50.730 Now they want to release the new editions of the books for this year, so now I need to add second edition 03:50.730 --> 03:51.690 for each book. 03:52.200 --> 03:55.650 So I'm going to use a range class to get the indexes like this. 03:56.650 --> 04:02.230 Now, I'm going to get the book at this index, then I'm going to add this second addition value to 04:02.230 --> 04:02.680 this book. 04:02.920 --> 04:03.890 All right, ready? 04:03.940 --> 04:04.600 Let's run it. 04:05.580 --> 04:12.390 Good, we have updated all the books, however, they want to display the last year's books along with 04:12.390 --> 04:17.100 this year's best books, so I need to create a copy of the prayer. 04:17.520 --> 04:19.100 Right, let's do that. 04:20.100 --> 04:24.960 So I'm going to create a new era here, then I'm going to assign the primary to this one. 04:25.260 --> 04:27.100 OK, I'm not done yet. 04:27.360 --> 04:31.620 I also need to change this variable here to the book's variable. 04:32.540 --> 04:36.900 It's because I only want to update the books are not depressed. 04:37.520 --> 04:37.920 OK. 04:38.090 --> 04:38.510 All right. 04:38.510 --> 04:39.760 Let me print the books. 04:42.700 --> 04:50.160 All right, let me run again now, notice that Provera didn't change only the books Erra has changed. 04:50.920 --> 04:56.860 This is because when now assigned Pereiro to books, Eryr Go has allocated a new array. 04:57.520 --> 05:03.850 Then it has copied all the elements of the primary to books so they are not connected. 05:04.540 --> 05:07.780 Changing one of them does not affect the other one. 05:08.380 --> 05:12.060 OK, Hipster's LE Bookstore has a new request. 05:12.430 --> 05:17.470 They have changed their minds and now they want to release four books this year. 05:18.100 --> 05:23.150 But the bookseller can only store three books because I have copied it from the primary. 05:23.350 --> 05:27.100 Right, so they have the same length, which is three. 05:27.340 --> 05:30.760 So I need to create a new speaker with four elements. 05:31.060 --> 05:31.450 Right. 05:31.630 --> 05:37.510 So I'm going to remove this declaration first, then I'm going to declare and era with four elements 05:37.630 --> 05:38.260 like this. 05:38.770 --> 05:39.450 OK, good. 05:39.460 --> 05:40.250 Let me read it again. 05:40.900 --> 05:46.180 The book is empty, of course, because it's a new era that I've created from scratch. 05:46.330 --> 05:46.710 Right. 05:47.590 --> 05:50.880 So I need to copy the books into it from the primary. 05:51.130 --> 05:51.490 Right. 05:52.180 --> 05:52.750 Let's do that. 05:53.290 --> 05:56.380 Let me first try to assign the primary to Boukhari. 05:56.770 --> 05:59.050 As you can see, it doesn't work there. 05:59.050 --> 06:00.430 Types are different. 06:00.520 --> 06:01.830 So what should I do? 06:02.760 --> 06:09.790 I need to copy the books manually, of course, so now I'm going to get the book title from the primary. 06:10.260 --> 06:17.190 All I need to do is to add an iteration variable to this range expression like this so it will get the 06:17.190 --> 06:18.720 next book from the primary. 06:19.530 --> 06:23.040 Now, let's add this be variable just before this value. 06:24.190 --> 06:25.920 Now, now it works. 06:25.920 --> 06:26.340 Cool. 06:27.180 --> 06:32.970 The book store owners also told me that the title of the next book that they are going to release this 06:32.970 --> 06:34.620 year is Awesomes. 06:35.110 --> 06:36.180 That's added as a. 06:38.820 --> 06:41.820 All right, let's try it again, cool, it works. 06:42.420 --> 06:43.860 All right, that's all for now. 06:44.160 --> 06:46.660 Thank you for watching so far, seeing the next picture.