WEBVTT

00:00.810 --> 00:06.120
As you learned earlier, there is an interesting a very interesting fact about arrays.

00:06.240 --> 00:11.060
So we can access the arrays element using a pointer.

00:11.070 --> 00:16.290
So as you may know, a pointer is a variable that holds the address.

00:16.980 --> 00:18.110
Instead of value.

00:18.120 --> 00:25.560
So and since we discussed earlier that each element in the array has its own address, we can access

00:25.560 --> 00:28.230
each race element using its address.

00:28.230 --> 00:35.520
So to use a pointer as an array, we need to initialize to it to hold an array as shown here.

00:35.520 --> 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

00:46.350 --> 00:47.460
array here.

00:49.300 --> 00:51.280
Or let's actually write it from zero.

00:51.760 --> 00:57.970
So, as you know, we previously we manipulated some of the things here we did.

00:58.800 --> 01:01.260
And actually let's clear the main method.

01:01.260 --> 01:02.220
So we want to use it.

01:02.430 --> 01:10.170
We will use it anywhere and we will also clear this that we changed it.

01:10.170 --> 01:14.100
So we changed index two and index three.

01:14.130 --> 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

01:23.100 --> 01:24.930
the 87 index.

01:24.930 --> 01:29.610
Two, we will write 8787.

01:31.230 --> 01:33.420
And 69.

01:33.600 --> 01:36.270
69.

01:38.430 --> 01:39.060
Here.

01:41.380 --> 01:45.370
So now we're going to create our array here.

01:45.370 --> 01:47.470
So let's actually comment this.

01:48.720 --> 01:52.380
Comments and we will create a new integer pointer array.

01:52.380 --> 01:54.240
So integer, Peter.

01:54.350 --> 01:56.850
Peter new integer.

01:57.240 --> 02:00.180
This is going to be five size of integer.

02:00.180 --> 02:02.690
So one, two, three, four, five.

02:02.700 --> 02:04.680
Size of five, not the index five.

02:04.680 --> 02:11.430
So if you have five, uh, size of array, then we have the from zero.

02:11.430 --> 02:16.170
This means our maximum index is four by default.

02:16.200 --> 02:23.710
So here now we're going to create this 25, 2148

02:24.340 --> 02:28.380
827 30 Uh, no.

02:28.380 --> 02:31.950
40 2148 827.

02:32.220 --> 02:34.950
The 69 and 35.

02:36.150 --> 02:39.110
So this is an initialization.

02:39.240 --> 02:49.080
We have a pointer named Peter that points to the first element of an array containing five elements

02:49.080 --> 02:49.650
here.

02:50.490 --> 02:51.480
So.

02:52.790 --> 02:56.930
However, the variable holds the first arrays element address at START.

02:56.930 --> 03:02.750
So to access the next address, we can increment Peter variables.

03:03.140 --> 03:03.500
So.

03:03.500 --> 03:14.870
Peter plus plus we can increment the Peter variable, um, so that it will point to the next element

03:14.870 --> 03:15.140
here.

03:15.140 --> 03:17.690
So it will point to next element.

03:17.720 --> 03:26.000
Actually, yeah, we can increment this and so it will point to the next element and next element here.

03:26.240 --> 03:30.830
So we can use the wildcard symbol before the pointer name.

03:30.830 --> 03:32.560
And as you can see here.

03:32.570 --> 03:33.710
So.

03:35.800 --> 03:37.810
Let's first actually create some.

03:40.400 --> 03:41.210
Here.

03:46.470 --> 03:51.450
Here we will create a print this variable C out.

03:52.370 --> 03:53.210
See out.

03:54.600 --> 03:57.840
PDR, PDR and inline.

03:58.140 --> 04:02.250
And thus we will print this without the disk.

04:02.940 --> 04:06.120
Without this, the wild card symbol.

04:06.120 --> 04:06.750
So.

04:06.780 --> 04:08.970
PDR and end line.

04:09.580 --> 04:10.720
End line here.

04:10.720 --> 04:16.800
So the former statement in this code will print out the value that pointer points to.

04:16.810 --> 04:18.680
So let's actually firstly compile it.

04:18.700 --> 04:22.630
CLS and G++.

04:22.660 --> 04:24.010
Main.cpp.

04:25.400 --> 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.

04:31.850 --> 04:37.190
So as we said earlier, the first this.

04:38.560 --> 04:39.700
So let's here.

04:39.700 --> 04:50.500
So this symbol p t r points to our 21.

04:50.500 --> 04:54.730
So the first element so equals the first.

04:55.720 --> 04:56.410
Element.

05:01.650 --> 05:04.370
However, if we write it like that.

05:04.380 --> 05:06.000
The P here.

05:07.290 --> 05:08.130
Peter.

05:08.250 --> 05:15.660
The Peter is just shows the entire address the address of in our memory that.

05:17.310 --> 05:19.200
Our array lives on it.

05:19.200 --> 05:23.270
So in this case it's going to print the address.

05:23.280 --> 05:25.380
So at.

05:26.080 --> 05:26.830
Rest.

05:28.300 --> 05:29.890
Of array.

05:33.010 --> 05:38.800
So this prints out the address of arrays, the second code line.

05:38.800 --> 05:45.490
And here this prints the first element, which is 21.

05:47.320 --> 05:51.460
So here we can access the value of each element.

05:52.330 --> 05:55.150
And the address as well as its index.

05:55.150 --> 05:58.180
So let's actually create some another example.

05:59.880 --> 06:00.570
Here.

06:00.600 --> 06:01.670
Let's, uh.

06:01.710 --> 06:02.220
Here.

06:02.220 --> 06:03.330
Clear that.

06:06.760 --> 06:07.330
Here.

06:07.330 --> 06:08.320
Clear that.

06:09.190 --> 06:09.970
Clear that.

06:09.970 --> 06:10.660
Clear that.

06:10.660 --> 06:11.530
Clear that.

06:25.570 --> 06:29.530
Here now, we will create something like that.

06:29.530 --> 06:32.170
So now we're going to create.

06:33.240 --> 06:33.900
Uh, the.

06:35.590 --> 06:41.220
Some code that we can access the value of each element and the address as well as the index.

06:41.230 --> 06:42.880
So the key out.

06:42.910 --> 06:43.350
Oops.

06:44.910 --> 06:46.110
The sea out.

06:49.170 --> 06:52.500
See out the r e here.

06:52.530 --> 06:58.680
E in this case, for example, to let's take E as a two and we will end line here.

06:58.710 --> 07:03.330
End line and see out tr.

07:04.660 --> 07:07.500
Again, he is a to here for example just.

07:07.860 --> 07:11.850
He also can be three, 4 or 0.

07:11.850 --> 07:15.980
But in this case it's going to print the address of our array here.

07:15.990 --> 07:23.220
So now let's actually go to CMD compiler application and run it.

07:24.570 --> 07:25.260
Here.

07:25.680 --> 07:29.160
So as you can see here, this prints.

07:29.160 --> 07:36.540
So in this case, our E was the E was equal to two.

07:36.540 --> 07:38.880
So we've written the two.

07:40.230 --> 07:44.790
Between these braces in the two code code lines.

07:44.790 --> 07:45.480
So.

07:46.280 --> 07:47.800
This is our.

07:49.880 --> 07:57.290
P t r, and this is our regular p r, which showed us the same result.

07:57.290 --> 08:01.490
If we use if you use that the.

08:03.420 --> 08:04.350
Index.

08:05.220 --> 08:06.330
We specified index.

08:06.330 --> 08:10.110
It will get us an same result here.

08:10.440 --> 08:18.930
So in next lecture we will create some code that we will initialize pointer, initialize the array length

08:18.930 --> 08:26.700
and we will also display each element by incrementing the pointer and we will move forward the pointer

08:26.700 --> 08:27.660
five times.

08:27.660 --> 08:29.400
So I'm waiting you in the next lecture.
