1 00:00:01,680 --> 00:00:07,890 An array is a series of elements with the same data type that is placed in contiguous memory locations. 2 00:00:07,890 --> 00:00:12,880 So this means that the memory location is assigned in consecutive memory blocks. 3 00:00:12,900 --> 00:00:18,690 Since it implements the contiguous memory locations, the elements of the array can be individually 4 00:00:18,690 --> 00:00:20,490 accessed by the index. 5 00:00:20,490 --> 00:00:23,730 So let's take a look at this diagram here. 6 00:00:25,330 --> 00:00:25,690 Here. 7 00:00:25,690 --> 00:00:28,610 Let's say we have the five array. 8 00:00:28,630 --> 00:00:32,470 So these are the memory addresses here. 9 00:00:32,470 --> 00:00:38,080 So let's actually write it, the memory actually here. 10 00:00:38,500 --> 00:00:44,940 So these are the memory addresses we will write here here by now. 11 00:00:44,950 --> 00:00:48,430 So these are the memory address. 12 00:00:49,610 --> 00:00:56,060 And we here we have the also we also have. 13 00:00:57,080 --> 00:01:07,700 The and are here at the bottom that we write as 012, three, four is indexed of our array. 14 00:01:07,970 --> 00:01:11,900 So here these are the index. 15 00:01:13,240 --> 00:01:16,330 And as you can see, let's actually put some variables in them. 16 00:01:16,450 --> 00:01:21,640 So here, let's say we have the 21. 17 00:01:22,060 --> 00:01:23,780 Oops, not like this. 18 00:01:23,800 --> 00:01:24,790 We just want it here. 19 00:01:24,790 --> 00:01:25,410 Marker. 20 00:01:25,420 --> 00:01:29,800 So here, let's say this is 21 here. 21 00:01:31,280 --> 00:01:32,660 21. 22 00:01:32,660 --> 00:01:37,730 And this one in the first index is 47. 23 00:01:38,510 --> 00:01:41,210 And then 87. 24 00:01:44,470 --> 00:01:46,120 69. 25 00:01:48,210 --> 00:01:49,080 And. 26 00:01:49,790 --> 00:01:51,590 35. 27 00:01:53,550 --> 00:01:53,860 Mm hmm. 28 00:01:54,560 --> 00:02:04,380 And here, as you can see here in this illustration, we have an array and containing five elements. 29 00:02:04,400 --> 00:02:11,060 So since the array uses zero zero based indexing, the index starts from zero. 30 00:02:11,960 --> 00:02:17,430 So this index is used to access the element value and also replace the element value. 31 00:02:17,450 --> 00:02:23,060 So the memory state address is state in the illustration is, for example, purposes only. 32 00:02:23,420 --> 00:02:25,070 You can see here. 33 00:02:25,730 --> 00:02:30,920 So this is just an example purposes only in your actual computer. 34 00:02:31,640 --> 00:02:34,700 In reality, the memory address might be different. 35 00:02:34,700 --> 00:02:39,650 So however, it illustrates that the memory allocation is contiguous here. 36 00:02:41,560 --> 00:02:46,720 But sometimes it might differentiate and like memory location might be random here, which you will 37 00:02:46,720 --> 00:02:50,220 learn about them in next lectures. 38 00:02:50,230 --> 00:02:58,140 So now if we want to access the preceding array or let's actually create this array in C plus plus code. 39 00:02:58,150 --> 00:02:59,410 So let's get started first. 40 00:02:59,410 --> 00:03:02,620 Actually, let's make it the bit right here. 41 00:03:02,650 --> 00:03:03,220 Oops. 42 00:03:03,250 --> 00:03:05,380 How can we select all of them? 43 00:03:06,010 --> 00:03:07,090 I guess we can't. 44 00:03:10,260 --> 00:03:11,610 Yes, we guess we. 45 00:03:12,950 --> 00:03:13,580 Here. 46 00:03:16,590 --> 00:03:17,460 These are the copy. 47 00:03:17,460 --> 00:03:19,830 Yeah, we can hear. 48 00:03:19,830 --> 00:03:21,270 So make this here. 49 00:03:21,360 --> 00:03:23,610 Get this marker here. 50 00:03:23,610 --> 00:03:25,080 Uh, the cursor here. 51 00:03:25,080 --> 00:03:28,860 So first we implemented using STD here. 52 00:03:29,630 --> 00:03:32,960 And also your stream because we're going to use the key out and other. 53 00:03:33,910 --> 00:03:34,570 Functions. 54 00:03:34,570 --> 00:03:37,900 And here we're going to initialize an array here. 55 00:03:37,900 --> 00:03:40,360 So our first array integer. 56 00:03:41,110 --> 00:03:42,460 Integer. 57 00:03:42,490 --> 00:03:47,200 Integer array here or my array and here. 58 00:03:47,200 --> 00:03:49,810 It's going to be the 21. 59 00:03:50,610 --> 00:03:51,750 47. 60 00:03:53,400 --> 00:03:58,770 47, 87, 69 and 35. 61 00:03:58,890 --> 00:04:05,070 And as you can see here, the IntelliJ idea tells us that this is here. 62 00:04:05,340 --> 00:04:11,010 Let's actually, as you can see here, the index zero here, index zero here. 63 00:04:12,760 --> 00:04:14,740 Index zero is 21. 64 00:04:14,980 --> 00:04:15,940 As you can see here. 65 00:04:15,940 --> 00:04:17,830 It writes it like that. 66 00:04:19,360 --> 00:04:20,230 Oh, here. 67 00:04:20,880 --> 00:04:22,560 Index is 21. 68 00:04:22,590 --> 00:04:26,520 The index one is 47. 69 00:04:26,550 --> 00:04:29,010 Index two is 87. 70 00:04:29,040 --> 00:04:35,790 The index three is 69 and index four is 35. 71 00:04:36,720 --> 00:04:37,440 Here. 72 00:04:37,440 --> 00:04:42,750 So now we need to access each element after this code here. 73 00:04:42,750 --> 00:04:49,560 So let's actually create a get the cursor here and now we're going to access elements with this key 74 00:04:49,740 --> 00:04:53,940 firstly, so we tell the user that we are array elements. 75 00:04:54,180 --> 00:04:59,280 Array elements are or array elements, just an array elements. 76 00:04:59,280 --> 00:05:00,660 And after that. 77 00:05:02,310 --> 00:05:06,000 Here in the line at the here. 78 00:05:06,970 --> 00:05:07,990 And now. 79 00:05:08,890 --> 00:05:10,250 We're going to create a for loop. 80 00:05:10,270 --> 00:05:23,170 So for integer for integer here, zero while the integer is E is less than size of our array, size 81 00:05:23,170 --> 00:05:27,730 of our array or my array size of my array. 82 00:05:27,760 --> 00:05:36,580 Then so size of we will also need to get an integer size so we will divide size of our pointer array 83 00:05:36,580 --> 00:05:38,980 here, my array. 84 00:05:39,280 --> 00:05:49,270 And after that we will increment e by one in each iteration and we will print this of course here array 85 00:05:49,300 --> 00:05:50,440 my array. 86 00:05:50,560 --> 00:05:58,090 My array here is E and here after that inline. 87 00:05:59,990 --> 00:06:00,220 Line. 88 00:06:01,860 --> 00:06:02,830 So that's it. 89 00:06:02,850 --> 00:06:05,970 So let's actually run our program and see what happens. 90 00:06:05,970 --> 00:06:08,220 So first let's go to Command Prompt. 91 00:06:11,320 --> 00:06:12,220 Full screen. 92 00:06:14,020 --> 00:06:15,160 Our file was. 93 00:06:15,160 --> 00:06:15,520 Yeah. 94 00:06:15,560 --> 00:06:19,180 G++ main.cpp a dot exe here. 95 00:06:19,180 --> 00:06:27,550 And as you can see here, array element starts from the 21 actually let's make is like that array elements 96 00:06:27,550 --> 00:06:29,260 after that new line. 97 00:06:29,260 --> 00:06:35,740 But instead of new line we can also write it like this and line here it's the it will give us an same 98 00:06:35,770 --> 00:06:41,220 output compile it again close and open a dot XM. 99 00:06:41,230 --> 00:06:49,720 So as you can see here, we have here our array elements is first array element is 21, then we have 100 00:06:49,720 --> 00:06:53,770 47, then we have 87. 101 00:06:54,940 --> 00:06:59,950 And then we have 69 and then we have 35 here. 102 00:07:00,670 --> 00:07:09,520 So now let's actually try to manipulate our array elements in the next lecture. 103 00:07:09,520 --> 00:07:11,380 So I'm waiting you in the next lecture.