WEBVTT 00:00.550 --> 00:03.910 Welcome in his lecture, I'm going to talk about what an array is. 00:04.420 --> 00:05.230 Let's get started. 00:05.770 --> 00:08.480 Think of this grid like the computer memory. 00:08.550 --> 00:14.740 OK, it has a lot of memory cells, which depends on the total capacity of your computer's memory. 00:15.250 --> 00:19.630 Now you're looking at an empty memory segment which doesn't store any value yet. 00:20.660 --> 00:27.530 Here, these diagonal lines are representing the memory cells, for example, one of them starts at 00:27.530 --> 00:31.910 this memory location and and at this memory location. 00:32.860 --> 00:38.510 By the way, not that each memory cell can only contain a value of one bite at most. 00:38.860 --> 00:43.020 We had talked about this earlier, but let me make you remember again. 00:43.570 --> 00:48.480 So when you declare a variable, go is going to store it in computer memory. 00:48.490 --> 00:48.790 Right. 00:49.570 --> 00:50.980 So here is about variable. 00:53.080 --> 00:54.180 And here is another one. 00:56.160 --> 01:01.130 As you can see, gold can allocate variables in different memory locations, right? 01:01.320 --> 01:08.730 For example, here go allocates the first variable in the hundredth memory cell and the second variable, 01:08.730 --> 01:14.600 five cells away from the first one in the one hundred and fifty memory cell. 01:15.210 --> 01:22.140 Now, let's see how those stories and error in the memory in computer memory and empty array value looks 01:22.140 --> 01:22.860 like this. 01:22.900 --> 01:28.980 As you can see, an array is a collection type that can store multiple values and unlike variables, 01:28.980 --> 01:32.820 Gobstoppers array elements in contiguous memory locations. 01:32.820 --> 01:38.400 For example, the first element is in the hundredth memory cell and the second element is in the one 01:38.400 --> 01:40.050 hundred first memory cell. 01:41.220 --> 01:45.430 Together, all of these values represent a single era value. 01:45.780 --> 01:52.860 So there is only one value here, actually, and through that you can access to its inner values. 01:53.010 --> 01:55.140 So what is the importance of this? 01:55.950 --> 01:57.960 Why this is a useful thing? 01:58.110 --> 02:03.780 It is because, for example, let's say you are passing a binary file format in there. 02:03.780 --> 02:07.740 You would need to represent the exact memory layout as that file format. 02:08.660 --> 02:15.560 Or let's say you need to store a low level data structure in memory as exactly as it is, so you can 02:15.560 --> 02:20.570 use an array to do so because an array is a direct representation of memory. 02:21.710 --> 02:29.780 This memory layout also allows Gore to store and fetch elements in a very fast manner because each element 02:29.780 --> 02:31.330 is right next to each other. 02:32.430 --> 02:37.030 So CPU can cache some part of it and then it can work faster. 02:37.800 --> 02:44.910 We won't go into details for these kind of stuff yet, but we'll take a look at these later on the course. 02:46.000 --> 02:53.140 Each element of this array is one by thread, so this error is total size is too wise because the size 02:53.140 --> 02:57.030 of an error is equal to the total size of all its elements. 02:57.340 --> 03:00.760 So go allocated to Biso memory block for this array. 03:01.810 --> 03:08.950 He resigned in 16 hours with two elements and let's say the first element is located in the underground 03:08.980 --> 03:15.070 memorizer, then the second element should have to be located in the 100 second memory cell. 03:15.190 --> 03:20.760 Right next to the previous value is because this time each element occupies two bytes. 03:21.340 --> 03:24.160 So these arrays, total size is for whites. 03:25.900 --> 03:28.930 Now, let's talk about Habanera Syntax works. 03:29.560 --> 03:31.960 This number represents these areas. 03:32.390 --> 03:36.730 OK, so this area can only store two elements at most. 03:38.160 --> 03:44.520 You can also use constant expressions when declaring the land of an era, for example, here, this 03:44.520 --> 03:50.760 area is Lancs is still too, by the way, Google calculates this value at the compile time. 03:51.570 --> 03:52.380 Let me explain. 03:52.590 --> 03:57.050 As you know, you can change a variables type wants to declare it right. 03:57.600 --> 04:02.640 It is the same for iRace since the land of an era also belongs to its type. 04:02.670 --> 04:09.390 It has to be a constant value and error is Langguth determines how many elements that you can store 04:09.390 --> 04:13.620 in an array it determines is fixed capacity. 04:14.340 --> 04:17.460 So once you set its length, you cannot change it. 04:17.460 --> 04:19.990 Later it becomes fixed. 04:20.370 --> 04:25.140 However, if you need a bigger array, you can declare a new one like this. 04:25.980 --> 04:30.150 Here for this array go resource three bytes of memory. 04:30.300 --> 04:36.360 However, if the elements were an entry to the world reserve twelve bytes of memory instead. 04:37.230 --> 04:39.480 Here is another example for this array. 04:39.510 --> 04:44.100 Gold reserves five bytes of memory because its length is five. 04:45.100 --> 04:52.290 And lastly, you cannot set an erase linked to a negative number because doing so is meaningless, right? 04:53.580 --> 05:01.550 OK, let's get back to our two elements right now, let's talk about the types and erase element type 05:01.560 --> 05:05.360 determines what type of values that you can store in that area. 05:05.550 --> 05:05.940 OK. 05:07.100 --> 05:13.370 For example, here, this area is type in the indicates that it can only store two elements. 05:14.720 --> 05:21.770 Remember, when you declare a variable without an initial value, it gets a zero value, right? 05:22.370 --> 05:24.840 It is the same with the error elements. 05:25.460 --> 05:31.970 So when you don't initialize the error elements, Gogu sets them to their zero values depending on the 05:31.970 --> 05:33.260 error element type. 05:33.770 --> 05:37.190 For example, here these errors elements are not initialized yet. 05:37.190 --> 05:37.540 Right. 05:38.150 --> 05:43.070 And because of these areas, element type is byte, which is a numeric type. 05:43.370 --> 05:47.780 So Gazette's all its elements of the array, two zeros automatically. 05:48.590 --> 05:52.250 By the way, you can use any type as the element type for an array. 05:52.440 --> 05:56.300 For example, here is a new era which can only store string values. 05:56.690 --> 06:02.210 Here, Thisara stores two empty string values because they haven't been initialized yet. 06:02.250 --> 06:02.600 OK. 06:03.950 --> 06:11.540 As I said, you can create an array with any element type, however, you cannot change its elements 06:11.700 --> 06:14.380 to another time once you declare it's OK. 06:14.990 --> 06:17.900 OK, now let's take a look at this example here. 06:17.900 --> 06:24.290 I'm trying to store and numeric value in this area, but I cannot do this because this OIRA's element 06:24.290 --> 06:26.000 type is now a string. 06:28.030 --> 06:34.360 All right, let's return to our byte array again now I'm going to show you how to access and change 06:34.360 --> 06:40.360 these areas elements, by the way, you can do so because each element of an array is an unnamed variable, 06:40.510 --> 06:42.850 so you can use them as variables. 06:43.070 --> 06:48.570 If it wasn't like that, then you wouldn't be able to access individual elements. 06:48.580 --> 06:49.570 Do you wonder why? 06:50.110 --> 06:56.010 It's because God doesn't allow you to access arbitrary memory locations by default. 06:56.200 --> 07:02.020 However, you can do so by using some dark magic, which is, by the way, not the best time to talk 07:02.020 --> 07:02.670 about it yet. 07:02.920 --> 07:08.950 So because God doesn't allow you to access arbitrary memory locations so you can get the individual 07:08.950 --> 07:13.020 elements from an array just by directly accessing the memory location. 07:13.690 --> 07:18.890 So instead of that go prolacta, another mechanism called index expressions, as you know. 07:18.940 --> 07:21.850 So through them you can access the array elements. 07:22.380 --> 07:23.050 All right. 07:23.080 --> 07:27.790 As you can see here, there are two bytes variable stored in this area right now. 07:27.790 --> 07:29.520 Let's learn how to work with them. 07:30.010 --> 07:32.440 Let's get the first element at index zero. 07:33.880 --> 07:36.670 Now, let's get the last element at index one. 07:37.860 --> 07:39.090 Wow, that was easy. 07:39.450 --> 07:46.020 OK, now let's find out the land of this area by using the built in land function like this, it returns 07:46.020 --> 07:48.600 to because there are two elements in this area. 07:49.020 --> 07:51.500 OK, now let's see what we can do. 07:51.600 --> 07:58.050 For example, let's try to get an element at indexed to this doesn't work because the index should be 07:58.050 --> 08:00.450 less than the length of the array. 08:00.480 --> 08:00.840 Right. 08:00.960 --> 08:03.210 Because the goal indexes start at zero. 08:03.240 --> 08:07.240 Now let's try to get an element in the minus one index. 08:08.040 --> 08:14.030 This doesn't work either because the index should be greater than or equal to zero. 08:15.040 --> 08:17.390 OK, let me show you an example here. 08:17.410 --> 08:23.200 I'm going to assign a value to the first element like this, so the first element becomes six. 08:23.650 --> 08:27.370 Now I'm going to subtract three from the second elements like this. 08:28.700 --> 08:35.000 So the second element becomes minus three, as you can see, when I get on elements, it acts like a 08:35.000 --> 08:38.150 variable or I wouldn't be able to assign to it. 08:38.470 --> 08:44.420 You can only use assignment operators when the left hand side is something that is stored in memory. 08:45.670 --> 08:47.580 Let me show you one more example. 08:47.980 --> 08:51.370 Now I'm going to assign a Sprink value to the first element. 08:52.030 --> 08:55.690 As you can see, I cannot do this, can I? 08:55.720 --> 08:59.970 Here is a string value, but these arrays element type is int. 09:00.190 --> 09:01.940 So there is a type mismatch here. 09:01.990 --> 09:05.490 That's why I couldn't assign a string value to this entry. 09:06.190 --> 09:06.810 All right. 09:06.820 --> 09:07.680 That's all for now. 09:07.720 --> 09:10.650 You learned a lot of useful knowledge about race. 09:11.140 --> 09:12.880 Now, let's take a quick break here. 09:12.910 --> 09:17.140 And in the next lecture, I'm going to show you examples in the coding, Ed.. 09:17.800 --> 09:19.120 See you there, Babbo.