1 00:00:00,810 --> 00:00:06,120 As you learned earlier, there is an interesting a very interesting fact about arrays. 2 00:00:06,240 --> 00:00:11,060 So we can access the arrays element using a pointer. 3 00:00:11,070 --> 00:00:16,290 So as you may know, a pointer is a variable that holds the address. 4 00:00:16,980 --> 00:00:18,110 Instead of value. 5 00:00:18,120 --> 00:00:25,560 So and since we discussed earlier that each element in the array has its own address, we can access 6 00:00:25,560 --> 00:00:28,230 each race element using its address. 7 00:00:28,230 --> 00:00:35,520 So to use a pointer as an array, we need to initialize to it to hold an array as shown here. 8 00:00:35,520 --> 00:00:46,300 So let's we're going to change it our this, my array and we will write this my for example my oxalate 9 00:00:46,350 --> 00:00:47,460 array here. 10 00:00:49,300 --> 00:00:51,280 Or let's actually write it from zero. 11 00:00:51,760 --> 00:00:57,970 So, as you know, we previously we manipulated some of the things here we did. 12 00:00:58,800 --> 00:01:01,260 And actually let's clear the main method. 13 00:01:01,260 --> 00:01:02,220 So we want to use it. 14 00:01:02,430 --> 00:01:10,170 We will use it anywhere and we will also clear this that we changed it. 15 00:01:10,170 --> 00:01:14,100 So we changed index two and index three. 16 00:01:14,130 --> 00:01:23,100 So in place of the index ten and as you can see it here, so in place of the index three, we will write 17 00:01:23,100 --> 00:01:24,930 the 87 index. 18 00:01:24,930 --> 00:01:29,610 Two, we will write 8787. 19 00:01:31,230 --> 00:01:33,420 And 69. 20 00:01:33,600 --> 00:01:36,270 69. 21 00:01:38,430 --> 00:01:39,060 Here. 22 00:01:41,380 --> 00:01:45,370 So now we're going to create our array here. 23 00:01:45,370 --> 00:01:47,470 So let's actually comment this. 24 00:01:48,720 --> 00:01:52,380 Comments and we will create a new integer pointer array. 25 00:01:52,380 --> 00:01:54,240 So integer, Peter. 26 00:01:54,350 --> 00:01:56,850 Peter new integer. 27 00:01:57,240 --> 00:02:00,180 This is going to be five size of integer. 28 00:02:00,180 --> 00:02:02,690 So one, two, three, four, five. 29 00:02:02,700 --> 00:02:04,680 Size of five, not the index five. 30 00:02:04,680 --> 00:02:11,430 So if you have five, uh, size of array, then we have the from zero. 31 00:02:11,430 --> 00:02:16,170 This means our maximum index is four by default. 32 00:02:16,200 --> 00:02:23,710 So here now we're going to create this 25, 2148 33 00:02:24,340 --> 00:02:28,380 827 30 Uh, no. 34 00:02:28,380 --> 00:02:31,950 40 2148 827. 35 00:02:32,220 --> 00:02:34,950 The 69 and 35. 36 00:02:36,150 --> 00:02:39,110 So this is an initialization. 37 00:02:39,240 --> 00:02:49,080 We have a pointer named Peter that points to the first element of an array containing five elements 38 00:02:49,080 --> 00:02:49,650 here. 39 00:02:50,490 --> 00:02:51,480 So. 40 00:02:52,790 --> 00:02:56,930 However, the variable holds the first arrays element address at START. 41 00:02:56,930 --> 00:03:02,750 So to access the next address, we can increment Peter variables. 42 00:03:03,140 --> 00:03:03,500 So. 43 00:03:03,500 --> 00:03:14,870 Peter plus plus we can increment the Peter variable, um, so that it will point to the next element 44 00:03:14,870 --> 00:03:15,140 here. 45 00:03:15,140 --> 00:03:17,690 So it will point to next element. 46 00:03:17,720 --> 00:03:26,000 Actually, yeah, we can increment this and so it will point to the next element and next element here. 47 00:03:26,240 --> 00:03:30,830 So we can use the wildcard symbol before the pointer name. 48 00:03:30,830 --> 00:03:32,560 And as you can see here. 49 00:03:32,570 --> 00:03:33,710 So. 50 00:03:35,800 --> 00:03:37,810 Let's first actually create some. 51 00:03:40,400 --> 00:03:41,210 Here. 52 00:03:46,470 --> 00:03:51,450 Here we will create a print this variable C out. 53 00:03:52,370 --> 00:03:53,210 See out. 54 00:03:54,600 --> 00:03:57,840 PDR, PDR and inline. 55 00:03:58,140 --> 00:04:02,250 And thus we will print this without the disk. 56 00:04:02,940 --> 00:04:06,120 Without this, the wild card symbol. 57 00:04:06,120 --> 00:04:06,750 So. 58 00:04:06,780 --> 00:04:08,970 PDR and end line. 59 00:04:09,580 --> 00:04:10,720 End line here. 60 00:04:10,720 --> 00:04:16,800 So the former statement in this code will print out the value that pointer points to. 61 00:04:16,810 --> 00:04:18,680 So let's actually firstly compile it. 62 00:04:18,700 --> 00:04:22,630 CLS and G++. 63 00:04:22,660 --> 00:04:24,010 Main.cpp. 64 00:04:25,400 --> 00:04:31,850 Edit And as you can see here, this is our pointer and this is our first element, as you can see here. 65 00:04:31,850 --> 00:04:37,190 So as we said earlier, the first this. 66 00:04:38,560 --> 00:04:39,700 So let's here. 67 00:04:39,700 --> 00:04:50,500 So this symbol p t r points to our 21. 68 00:04:50,500 --> 00:04:54,730 So the first element so equals the first. 69 00:04:55,720 --> 00:04:56,410 Element. 70 00:05:01,650 --> 00:05:04,370 However, if we write it like that. 71 00:05:04,380 --> 00:05:06,000 The P here. 72 00:05:07,290 --> 00:05:08,130 Peter. 73 00:05:08,250 --> 00:05:15,660 The Peter is just shows the entire address the address of in our memory that. 74 00:05:17,310 --> 00:05:19,200 Our array lives on it. 75 00:05:19,200 --> 00:05:23,270 So in this case it's going to print the address. 76 00:05:23,280 --> 00:05:25,380 So at. 77 00:05:26,080 --> 00:05:26,830 Rest. 78 00:05:28,300 --> 00:05:29,890 Of array. 79 00:05:33,010 --> 00:05:38,800 So this prints out the address of arrays, the second code line. 80 00:05:38,800 --> 00:05:45,490 And here this prints the first element, which is 21. 81 00:05:47,320 --> 00:05:51,460 So here we can access the value of each element. 82 00:05:52,330 --> 00:05:55,150 And the address as well as its index. 83 00:05:55,150 --> 00:05:58,180 So let's actually create some another example. 84 00:05:59,880 --> 00:06:00,570 Here. 85 00:06:00,600 --> 00:06:01,670 Let's, uh. 86 00:06:01,710 --> 00:06:02,220 Here. 87 00:06:02,220 --> 00:06:03,330 Clear that. 88 00:06:06,760 --> 00:06:07,330 Here. 89 00:06:07,330 --> 00:06:08,320 Clear that. 90 00:06:09,190 --> 00:06:09,970 Clear that. 91 00:06:09,970 --> 00:06:10,660 Clear that. 92 00:06:10,660 --> 00:06:11,530 Clear that. 93 00:06:25,570 --> 00:06:29,530 Here now, we will create something like that. 94 00:06:29,530 --> 00:06:32,170 So now we're going to create. 95 00:06:33,240 --> 00:06:33,900 Uh, the. 96 00:06:35,590 --> 00:06:41,220 Some code that we can access the value of each element and the address as well as the index. 97 00:06:41,230 --> 00:06:42,880 So the key out. 98 00:06:42,910 --> 00:06:43,350 Oops. 99 00:06:44,910 --> 00:06:46,110 The sea out. 100 00:06:49,170 --> 00:06:52,500 See out the r e here. 101 00:06:52,530 --> 00:06:58,680 E in this case, for example, to let's take E as a two and we will end line here. 102 00:06:58,710 --> 00:07:03,330 End line and see out tr. 103 00:07:04,660 --> 00:07:07,500 Again, he is a to here for example just. 104 00:07:07,860 --> 00:07:11,850 He also can be three, 4 or 0. 105 00:07:11,850 --> 00:07:15,980 But in this case it's going to print the address of our array here. 106 00:07:15,990 --> 00:07:23,220 So now let's actually go to CMD compiler application and run it. 107 00:07:24,570 --> 00:07:25,260 Here. 108 00:07:25,680 --> 00:07:29,160 So as you can see here, this prints. 109 00:07:29,160 --> 00:07:36,540 So in this case, our E was the E was equal to two. 110 00:07:36,540 --> 00:07:38,880 So we've written the two. 111 00:07:40,230 --> 00:07:44,790 Between these braces in the two code code lines. 112 00:07:44,790 --> 00:07:45,480 So. 113 00:07:46,280 --> 00:07:47,800 This is our. 114 00:07:49,880 --> 00:07:57,290 P t r, and this is our regular p r, which showed us the same result. 115 00:07:57,290 --> 00:08:01,490 If we use if you use that the. 116 00:08:03,420 --> 00:08:04,350 Index. 117 00:08:05,220 --> 00:08:06,330 We specified index. 118 00:08:06,330 --> 00:08:10,110 It will get us an same result here. 119 00:08:10,440 --> 00:08:18,930 So in next lecture we will create some code that we will initialize pointer, initialize the array length 120 00:08:18,930 --> 00:08:26,700 and we will also display each element by incrementing the pointer and we will move forward the pointer 121 00:08:26,700 --> 00:08:27,660 five times. 122 00:08:27,660 --> 00:08:29,400 So I'm waiting you in the next lecture.