Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,180 --> 00:00:03,010
What is going on, guys, in this video?
2
00:00:03,030 --> 00:00:10,160
I would like to teach you how our famous two dimensional array is actually being stored in memory.
3
00:00:10,830 --> 00:00:16,760
On one hand, it seems that it's stored as a matrix or a table with the rows and columns.
4
00:00:17,160 --> 00:00:22,020
But we will see that it is actually a little bit different than what it looks like.
5
00:00:22,050 --> 00:00:30,090
And the understanding of this topic is so important both for you as a future programmer with good skills
6
00:00:30,090 --> 00:00:34,860
as well as a preparation for your future interviews questions.
7
00:00:34,890 --> 00:00:43,050
You see, a lot of interviews regarding C programming language include some tricky questions about two
8
00:00:43,050 --> 00:00:49,730
dimensional arrays and this topic of the physical representation in memory is one of them.
9
00:00:50,280 --> 00:00:52,370
So make sure you're prepared.
10
00:00:52,620 --> 00:00:55,170
You'll thank me for that later.
11
00:00:55,530 --> 00:00:56,480
All right.
12
00:00:56,490 --> 00:01:00,070
So now let's ask Biggin.
13
00:01:00,150 --> 00:01:08,070
OK, so to do that, OK, to understand the memory representation, let us quickly recall our usage
14
00:01:08,070 --> 00:01:10,020
of one dimensional arrays.
15
00:01:10,560 --> 00:01:18,660
So if, for example, we declared in arrays such as in ARRL and five elements, then in this case what
16
00:01:18,660 --> 00:01:26,040
happened is that we've created five elements in a sequence store, the one after the other in the memory
17
00:01:26,040 --> 00:01:27,480
of our computer.
18
00:01:27,780 --> 00:01:35,070
And we know that we can access each of the arrays elements by using indexing, for example, IRR at
19
00:01:35,070 --> 00:01:36,180
Index zero.
20
00:01:36,180 --> 00:01:43,710
And these will give us the access to the first element of the array ARRL, X1 and the axis will.
21
00:01:43,710 --> 00:01:47,160
It will access the second element and so on.
22
00:01:47,670 --> 00:01:53,590
And also another thing that we can do is to print evere addresses.
23
00:01:53,760 --> 00:02:01,410
So if, for example, we are going to print the address of the first two elements by using printf element,
24
00:02:01,410 --> 00:02:08,520
one address equals to percentage value and the address of the first element and the address of the second
25
00:02:08,520 --> 00:02:08,970
element.
26
00:02:09,270 --> 00:02:17,010
And we use here the percentage value just to print the addressing some decimal representation so that
27
00:02:17,340 --> 00:02:23,810
it will be just simply easier for you to understand the concept that I'm about to teach you.
28
00:02:24,330 --> 00:02:30,030
And of course, for those of you who are already familiar with the usage of percentage value, there
29
00:02:30,060 --> 00:02:36,210
are, of course, fewer nuances that I don't talk about here, because that's not the point of this
30
00:02:36,210 --> 00:02:36,960
explanation.
31
00:02:36,960 --> 00:02:46,710
So simply refer to it as just the printing of the address of an element in just some sort of decimal
32
00:02:46,710 --> 00:02:47,730
representation.
33
00:02:48,150 --> 00:02:53,700
So anyway, let's say that the address of the first element was three thousand.
34
00:02:54,540 --> 00:03:00,870
Then in this case, the address of the second element would be three thousand and four and three thousand
35
00:03:00,870 --> 00:03:02,130
eight and so on.
36
00:03:02,730 --> 00:03:11,220
And basically that's the case since it's an array of individuals and every integer consumes for bytes
37
00:03:11,220 --> 00:03:12,010
of memory.
38
00:03:12,510 --> 00:03:19,860
So if you would like to if you would print the addresses of the other elements in these array, you
39
00:03:19,860 --> 00:03:26,850
will come to see that they are kind of organized one after the other in the memory, which is exactly
40
00:03:26,850 --> 00:03:28,200
what we know.
41
00:03:28,200 --> 00:03:28,810
Right.
42
00:03:28,890 --> 00:03:36,390
But now what will happen if we will create a two dimensional way with the two rows and three columns
43
00:03:36,390 --> 00:03:40,660
and try to print the addresses of each of these elements.
44
00:03:41,250 --> 00:03:44,550
But before we do so, just one thing that I want to ask you.
45
00:03:44,700 --> 00:03:46,620
Please stop the video right now.
46
00:03:46,710 --> 00:03:55,920
Go 10, 15 seconds to count where we spoke about one dimensional arrays and the addresses and just run
47
00:03:55,920 --> 00:03:59,060
these part of code on your computer.
48
00:03:59,070 --> 00:04:06,150
So around these code on your idea and make sure that you understand the results that are being printed
49
00:04:06,870 --> 00:04:08,730
and you understand everything that you see.
50
00:04:08,760 --> 00:04:13,610
OK, so let's get back here to our two dimensional array.
51
00:04:13,800 --> 00:04:20,790
So here we just created a two dimensional array and we print the addresses of the elements of each of
52
00:04:20,790 --> 00:04:22,250
the elements of this array.
53
00:04:22,500 --> 00:04:28,620
So we print the addresses on the first row and then the addresses on the second row and so on.
54
00:04:29,010 --> 00:04:37,230
And surprisingly, what we can see here is that all the elements of the two dimensional arrays of the
55
00:04:37,230 --> 00:04:41,760
two-dimensional array are simply stored one after the other.
56
00:04:41,940 --> 00:04:47,610
OK, so that's what happens behind the scenes in the actual memory of your computer, you can see that
57
00:04:47,610 --> 00:04:58,590
the rest of our elements at Rosero and column zero is just 16 at the end of them, twenty twenty four.
58
00:04:58,740 --> 00:04:59,640
And then at the.
59
00:04:59,860 --> 00:05:03,540
You know, it's kind of it continues, right?
60
00:05:03,580 --> 00:05:12,070
So if we come to break it even further, we can see that these two dimensional representation, the
61
00:05:12,070 --> 00:05:19,780
representation that is easier for us to imagine, is actually stored like this as a sequence in the
62
00:05:19,780 --> 00:05:21,470
memory of your computer.
63
00:05:21,520 --> 00:05:30,760
And ah, if we wanted to take a real look at how these two dimensional matrix for two dimensional array
64
00:05:30,940 --> 00:05:34,670
looks like in memory, it would be something like this.
65
00:05:34,720 --> 00:05:41,620
OK, so that's basically the representation in the memory of the computer behind the scenes.
66
00:05:41,890 --> 00:05:49,090
OK, so two dimensional array is we are are like, you know, reading it and thinking about it as the
67
00:05:49,510 --> 00:05:53,110
greed of columns and rows actually behind the scenes.
68
00:05:53,110 --> 00:05:55,330
It's just like that.
69
00:05:55,450 --> 00:06:01,840
So let's just pointing it out here so you can see here of it, everything seems to be sequential.
70
00:06:01,840 --> 00:06:07,300
Four bytes, one of them or the other or so meaning we think about a two dimensional array like this,
71
00:06:07,480 --> 00:06:13,450
but actually behind the scenes, it is thought is a sequence of elements, one after the other.
72
00:06:13,570 --> 00:06:17,020
And that's the first row and that's the second row.
73
00:06:17,260 --> 00:06:20,980
And you access the first row by using that index zero.
74
00:06:20,980 --> 00:06:27,910
And if you want to access each of these columns, so you access it like mad at index zero zero zero
75
00:06:27,910 --> 00:06:29,830
one zero two in here.
76
00:06:29,860 --> 00:06:35,560
OK, here, guys, I just want you to understand that it's not going to be three, four, five, OK?
77
00:06:35,590 --> 00:06:41,920
I just left it from the previous example, but it will be again, zero one two.
78
00:06:41,950 --> 00:06:49,630
So here is not three four five zero one two because we are accessing MAT at index one, which is row
79
00:06:49,630 --> 00:06:52,870
one row with the index one, which is the second row.
80
00:06:53,020 --> 00:06:56,020
And we are going to access each of the columns.
81
00:06:56,020 --> 00:07:00,500
So zero should be here, one should be here and two should be here.
82
00:07:00,530 --> 00:07:10,150
OK, so basically this is a very important video on how the memory represented behind the scenes for
83
00:07:10,150 --> 00:07:13,060
The Matrix and for the two dimensional array.
84
00:07:13,180 --> 00:07:21,370
Very important to understand for some reason I've encountered that interviewers really like to ask questions
85
00:07:21,370 --> 00:07:29,080
which are pretty much to check your understanding if you really understand the the core and what happens
86
00:07:29,080 --> 00:07:34,170
behind the scenes, and not only to initialize and use a two dimensional matrix.
87
00:07:34,870 --> 00:07:40,690
So thank you guys for watching and I wish you good luck if you're going to an interview or you are going
88
00:07:40,690 --> 00:07:43,120
for some exams and.
89
00:07:43,660 --> 00:07:44,830
Yeah, this is it.
90
00:07:45,070 --> 00:07:45,640
Goodbye.
9562
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.