WEBVTT

00:01.680 --> 00:07.890
An array is a series of elements with the same data type that is placed in contiguous memory locations.

00:07.890 --> 00:12.880
So this means that the memory location is assigned in consecutive memory blocks.

00:12.900 --> 00:18.690
Since it implements the contiguous memory locations, the elements of the array can be individually

00:18.690 --> 00:20.490
accessed by the index.

00:20.490 --> 00:23.730
So let's take a look at this diagram here.

00:25.330 --> 00:25.690
Here.

00:25.690 --> 00:28.610
Let's say we have the five array.

00:28.630 --> 00:32.470
So these are the memory addresses here.

00:32.470 --> 00:38.080
So let's actually write it, the memory actually here.

00:38.500 --> 00:44.940
So these are the memory addresses we will write here here by now.

00:44.950 --> 00:48.430
So these are the memory address.

00:49.610 --> 00:56.060
And we here we have the also we also have.

00:57.080 --> 01:07.700
The and are here at the bottom that we write as 012, three, four is indexed of our array.

01:07.970 --> 01:11.900
So here these are the index.

01:13.240 --> 01:16.330
And as you can see, let's actually put some variables in them.

01:16.450 --> 01:21.640
So here, let's say we have the 21.

01:22.060 --> 01:23.780
Oops, not like this.

01:23.800 --> 01:24.790
We just want it here.

01:24.790 --> 01:25.410
Marker.

01:25.420 --> 01:29.800
So here, let's say this is 21 here.

01:31.280 --> 01:32.660
21.

01:32.660 --> 01:37.730
And this one in the first index is 47.

01:38.510 --> 01:41.210
And then 87.

01:44.470 --> 01:46.120
69.

01:48.210 --> 01:49.080
And.

01:49.790 --> 01:51.590
35.

01:53.550 --> 01:53.860
Mm hmm.

01:54.560 --> 02:04.380
And here, as you can see here in this illustration, we have an array and containing five elements.

02:04.400 --> 02:11.060
So since the array uses zero zero based indexing, the index starts from zero.

02:11.960 --> 02:17.430
So this index is used to access the element value and also replace the element value.

02:17.450 --> 02:23.060
So the memory state address is state in the illustration is, for example, purposes only.

02:23.420 --> 02:25.070
You can see here.

02:25.730 --> 02:30.920
So this is just an example purposes only in your actual computer.

02:31.640 --> 02:34.700
In reality, the memory address might be different.

02:34.700 --> 02:39.650
So however, it illustrates that the memory allocation is contiguous here.

02:41.560 --> 02:46.720
But sometimes it might differentiate and like memory location might be random here, which you will

02:46.720 --> 02:50.220
learn about them in next lectures.

02:50.230 --> 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.

02:58.150 --> 02:59.410
So let's get started first.

02:59.410 --> 03:02.620
Actually, let's make it the bit right here.

03:02.650 --> 03:03.220
Oops.

03:03.250 --> 03:05.380
How can we select all of them?

03:06.010 --> 03:07.090
I guess we can't.

03:10.260 --> 03:11.610
Yes, we guess we.

03:12.950 --> 03:13.580
Here.

03:16.590 --> 03:17.460
These are the copy.

03:17.460 --> 03:19.830
Yeah, we can hear.

03:19.830 --> 03:21.270
So make this here.

03:21.360 --> 03:23.610
Get this marker here.

03:23.610 --> 03:25.080
Uh, the cursor here.

03:25.080 --> 03:28.860
So first we implemented using STD here.

03:29.630 --> 03:32.960
And also your stream because we're going to use the key out and other.

03:33.910 --> 03:34.570
Functions.

03:34.570 --> 03:37.900
And here we're going to initialize an array here.

03:37.900 --> 03:40.360
So our first array integer.

03:41.110 --> 03:42.460
Integer.

03:42.490 --> 03:47.200
Integer array here or my array and here.

03:47.200 --> 03:49.810
It's going to be the 21.

03:50.610 --> 03:51.750
47.

03:53.400 --> 03:58.770
47, 87, 69 and 35.

03:58.890 --> 04:05.070
And as you can see here, the IntelliJ idea tells us that this is here.

04:05.340 --> 04:11.010
Let's actually, as you can see here, the index zero here, index zero here.

04:12.760 --> 04:14.740
Index zero is 21.

04:14.980 --> 04:15.940
As you can see here.

04:15.940 --> 04:17.830
It writes it like that.

04:19.360 --> 04:20.230
Oh, here.

04:20.880 --> 04:22.560
Index is 21.

04:22.590 --> 04:26.520
The index one is 47.

04:26.550 --> 04:29.010
Index two is 87.

04:29.040 --> 04:35.790
The index three is 69 and index four is 35.

04:36.720 --> 04:37.440
Here.

04:37.440 --> 04:42.750
So now we need to access each element after this code here.

04:42.750 --> 04:49.560
So let's actually create a get the cursor here and now we're going to access elements with this key

04:49.740 --> 04:53.940
firstly, so we tell the user that we are array elements.

04:54.180 --> 04:59.280
Array elements are or array elements, just an array elements.

04:59.280 --> 05:00.660
And after that.

05:02.310 --> 05:06.000
Here in the line at the here.

05:06.970 --> 05:07.990
And now.

05:08.890 --> 05:10.250
We're going to create a for loop.

05:10.270 --> 05:23.170
So for integer for integer here, zero while the integer is E is less than size of our array, size

05:23.170 --> 05:27.730
of our array or my array size of my array.

05:27.760 --> 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

05:36.580 --> 05:38.980
here, my array.

05:39.280 --> 05:49.270
And after that we will increment e by one in each iteration and we will print this of course here array

05:49.300 --> 05:50.440
my array.

05:50.560 --> 05:58.090
My array here is E and here after that inline.

05:59.990 --> 06:00.220
Line.

06:01.860 --> 06:02.830
So that's it.

06:02.850 --> 06:05.970
So let's actually run our program and see what happens.

06:05.970 --> 06:08.220
So first let's go to Command Prompt.

06:11.320 --> 06:12.220
Full screen.

06:14.020 --> 06:15.160
Our file was.

06:15.160 --> 06:15.520
Yeah.

06:15.560 --> 06:19.180
G++ main.cpp a dot exe here.

06:19.180 --> 06:27.550
And as you can see here, array element starts from the 21 actually let's make is like that array elements

06:27.550 --> 06:29.260
after that new line.

06:29.260 --> 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

06:35.770 --> 06:41.220
output compile it again close and open a dot XM.

06:41.230 --> 06:49.720
So as you can see here, we have here our array elements is first array element is 21, then we have

06:49.720 --> 06:53.770
47, then we have 87.

06:54.940 --> 06:59.950
And then we have 69 and then we have 35 here.

07:00.670 --> 07:09.520
So now let's actually try to manipulate our array elements in the next lecture.

07:09.520 --> 07:11.380
So I'm waiting you in the next lecture.
