Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
What is going on, guys, in this video?
I would like to teach you how our famous two dimensional array is actually being stored in memory.
On one hand, it seems that it's stored as a matrix or a table with the rows and columns.
But we will see that it is actually a little bit different than what it looks like.
And the understanding of this topic is so important both for you as a future programmer with good skills
as well as a preparation for your future interviews questions.
You see, a lot of interviews regarding C programming language include some tricky questions about two
dimensional arrays and this topic of the physical representation in memory is one of them.
So make sure you're prepared.
You'll thank me for that later.
All right.
So now let's ask Biggin.
OK, so to do that, OK, to understand the memory representation, let us quickly recall our usage
of one dimensional arrays.
So if, for example, we declared in arrays such as in ARRL and five elements, then in this case what
happened is that we've created five elements in a sequence store, the one after the other in the memory
of our computer.
And we know that we can access each of the arrays elements by using indexing, for example, IRR at
Index zero.
And these will give us the access to the first element of the array ARRL, X1 and the axis will.
It will access the second element and so on.
And also another thing that we can do is to print evere addresses.
So if, for example, we are going to print the address of the first two elements by using printf element,
one address equals to percentage value and the address of the first element and the address of the second
element.
And we use here the percentage value just to print the addressing some decimal representation so that
it will be just simply easier for you to understand the concept that I'm about to teach you.
And of course, for those of you who are already familiar with the usage of percentage value, there
are, of course, fewer nuances that I don't talk about here, because that's not the point of this
explanation.
So simply refer to it as just the printing of the address of an element in just some sort of decimal
representation.
So anyway, let's say that the address of the first element was three thousand.
Then in this case, the address of the second element would be three thousand and four and three thousand
eight and so on.
And basically that's the case since it's an array of individuals and every integer consumes for bytes
of memory.
So if you would like to if you would print the addresses of the other elements in these array, you
will come to see that they are kind of organized one after the other in the memory, which is exactly
what we know.
Right.
But now what will happen if we will create a two dimensional way with the two rows and three columns
and try to print the addresses of each of these elements.
But before we do so, just one thing that I want to ask you.
Please stop the video right now.
Go 10, 15 seconds to count where we spoke about one dimensional arrays and the addresses and just run
these part of code on your computer.
So around these code on your idea and make sure that you understand the results that are being printed
and you understand everything that you see.
OK, so let's get back here to our two dimensional array.
So here we just created a two dimensional array and we print the addresses of the elements of each of
the elements of this array.
So we print the addresses on the first row and then the addresses on the second row and so on.
And surprisingly, what we can see here is that all the elements of the two dimensional arrays of the
two-dimensional array are simply stored one after the other.
OK, so that's what happens behind the scenes in the actual memory of your computer, you can see that
the rest of our elements at Rosero and column zero is just 16 at the end of them, twenty twenty four.
And then at the.
You know, it's kind of it continues, right?
So if we come to break it even further, we can see that these two dimensional representation, the
representation that is easier for us to imagine, is actually stored like this as a sequence in the
memory of your computer.
And ah, if we wanted to take a real look at how these two dimensional matrix for two dimensional array
looks like in memory, it would be something like this.
OK, so that's basically the representation in the memory of the computer behind the scenes.
OK, so two dimensional array is we are are like, you know, reading it and thinking about it as the
greed of columns and rows actually behind the scenes.
It's just like that.
So let's just pointing it out here so you can see here of it, everything seems to be sequential.
Four bytes, one of them or the other or so meaning we think about a two dimensional array like this,
but actually behind the scenes, it is thought is a sequence of elements, one after the other.
And that's the first row and that's the second row.
And you access the first row by using that index zero.
And if you want to access each of these columns, so you access it like mad at index zero zero zero
one zero two in here.
OK, here, guys, I just want you to understand that it's not going to be three, four, five, OK?
I just left it from the previous example, but it will be again, zero one two.
So here is not three four five zero one two because we are accessing MAT at index one, which is row
one row with the index one, which is the second row.
And we are going to access each of the columns.
So zero should be here, one should be here and two should be here.
OK, so basically this is a very important video on how the memory represented behind the scenes for
The Matrix and for the two dimensional array.
Very important to understand for some reason I've encountered that interviewers really like to ask questions
which are pretty much to check your understanding if you really understand the the core and what happens
behind the scenes, and not only to initialize and use a two dimensional matrix.
So thank you guys for watching and I wish you good luck if you're going to an interview or you are going
for some exams and.
Yeah, this is it.
Goodbye.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.