WEBVTT

00:00.700 --> 00:06.630
We've learned before that arrays are a contiguous sequence of single variables.

00:07.090 --> 00:10.500
These arrays are called one dimensional arrays.

00:10.830 --> 00:12.940
You can have more than one dimension.

00:13.340 --> 00:23.680
And let's say we wanted a two dimensional array type Gerais just call and entry to the.

00:23.910 --> 00:32.010
And just like for we have the size and we have another size.

00:32.480 --> 00:41.440
So this theory actually has 100 elements so there are 10 rows in 10 columns.

00:42.520 --> 00:49.140
The first 10 represents the number of rows and the next is the number of columns.

00:50.150 --> 00:53.440
So for each row there are 10 columns.

00:53.480 --> 00:55.560
Think of it that way.

00:55.570 --> 01:08.610
This is effectively a grid of of in this case integers that can be set that can have values k just like

01:08.790 --> 01:10.820
the one dimensional counterparts.

01:10.890 --> 01:13.240
It's also contiguous in memory.

01:13.620 --> 01:19.460
Here's my mental model for two D-Rays this here

01:23.060 --> 01:31.880
the indices start at the top left and go from right to left in the columns and from top to bottom for

01:32.070 --> 01:38.490
the rows just notice like one dimensional array is that indices start at zero.

01:39.020 --> 01:54.510
And so array that's it Ray to d of 0 0 is the very top top left element and say

01:56.780 --> 02:02.340
re to d of 0 1

02:04.920 --> 02:09.410
would be the top middle element in this example.

02:11.460 --> 02:26.700
And Ray we have two one would be the bottom middle in this example really two dimensional array is working

02:27.000 --> 02:30.260
the same as one dimensional arrays just in two directions.

02:31.240 --> 02:41.910
The indices go from zero to rolling minus one for rows and zero to column length minus one for columns.

02:41.920 --> 02:46.600
So here's how you would initialize a two dimensional array.

02:46.940 --> 02:48.690
So it's this

02:51.490 --> 02:55.980
and say we had another one let's get this well

03:00.710 --> 03:05.960
in what's called Judy it has to

03:08.640 --> 03:19.650
linked to in the row and the length three in the call games that's always row so your column is here.

03:21.680 --> 03:28.750
So here's how you'd initialize this say in three

03:31.700 --> 03:41.010
six K or six total elements in this array.

03:41.200 --> 03:41.630
Right.

03:42.910 --> 03:51.680
So in this case it would make a two dimensional array of two by three two rows and three columns of

03:51.710 --> 03:52.490
like or.

03:52.630 --> 03:53.230
Yeah.

03:53.290 --> 03:59.880
And just like I said for and one to three would be in the first row.

04:00.210 --> 04:00.790
OK.

04:01.100 --> 04:09.210
So this would go into the first row and four five six would be in the second row.

04:10.240 --> 04:18.610
And here's kind of a more intuitive way to initialize if we just say like this

04:23.650 --> 04:27.970
then this is also a good way to initialize.

04:28.330 --> 04:37.480
So you can group entire rows gather as well using these braces go even crazier than just two dimensions.

04:37.480 --> 04:40.590
We can have as many dimensions as we want it really.

04:40.600 --> 04:46.950
So we could have say hooray three like this.

04:46.960 --> 04:52.940
So do three and four.

04:52.970 --> 04:55.950
So this creates a three dimensional array.

04:56.120 --> 05:03.200
It has two rows of three by four a raise if you want to think of it that way Oregon.

05:03.200 --> 05:07.480
Think of it as having two rows three columns and four dead.

05:09.170 --> 05:15.380
If you want to think of it that way as well we won't be using anything above a two dimensional array

05:15.390 --> 05:19.570
but you can technically have as many dimensions that you want.

05:20.100 --> 05:24.290
So we'll see how those interact with pointers in the next lecture.
