Malcolm in his lecture, I'm going to talk about arrays of arrays or in other words, multidimensional
arrays.
So a multidimensional array is an ordinary array that contains other arrays.
Let me show you an example.
Imagine that there are two areas like these, once this area literally create these areas, each one
stores the last three grades of two students.
All right.
Now I'm going to create a multidimensional array by using these areas here to create a multidimensional
area.
I'm going to use an area literal such as this one.
I'll explain this syntax shortly.
No worries, so these are literal creates a multidimensional array like this one, you can think of
this as an array of arrays or as a table or as a matrix from math and so on.
Outer area contains the inner arrays and its type looks like this.
It is two elements of three integer arrays, OK?
The first row here contains the first inner array.
And the second row contains the second Inotera.
You can access to the first Inotera by using the first index of the outer area.
OK.
And you can access the second in L.A. by using the second index of the outer.
As you know, this highlighted part describes the area's length, so this area should only contain two
inner areas.
However, as you know, you can change this to any length at the compile time, of course.
As you also know, this is the element type of the area, it determines the type of injuries this can
be anytime.
This is actually just a type this is just one element I do not think of.
It is something else.
This is the same thing that we have learned in the previous lectures.
OK.
So these are the types of injuries, for example, here, all the injuries have the same types, right,
is because the parents Herries type or the outrace type is also through injury.
So in a multidimensional way, you can only store injuries with the same types.
By the way, is golems simplistic.
Let me show you one more thing.
Gore knows that the errors here have the same types, right, it knows it from the outer erase element.
So Gore allows you to omit the types for the inner errors altogether.
This error, literal syntax, is the same as the previous one.
So it creates the very same error.
So you can Ormet the types Gore implicitly adds down for you.
Now, I'm going to show you a few examples inside the court, Ed.
Our goal is to find the average grade of all the given students.
OK.
So now I'm going to create, to erase.
This one is for the first students grades and this one is for the second students grades.
I declared these areas using flawed six to four because I don't want to convert them again in the rest
of the court.
OK, you will see about it.
So I want to calculate the average grade, so now I'm going to declare a flawed six to four variable,
then I'm going to sum all the grades of the first student like this.
Don, I'm going to do the same thing for a second student as.
OK, now I've calculated the total grades for every student to find out the average.
I need to divide this into the total number of grades.
Right.
Let's find out the total number of grades that I'm going to declare a constant here.
Remember when you used the land function with an error, it returns a constant integer and I have used
a constant here also because constants are compile time values, unlike variables, they don't allocate
new memory space.
So now I'm going to get the length of the first student.
This will work because each student has the same number of grades.
Then I'm going to multiply it with two because there are two students.
OK, let me print it.
Here, I need to divide the total grades with the total number of grades like this.
However, there is a type mismatch here, this land function returns an end, whereas the same variable
is a flawed six to four.
So it is better to convert it here in this constant because I may need it again.
It's better to convert it once now.
It's OK.
Let me run this school.
The average grade is 5.5.
However, as you know, this is not good.
Think about what would happen if I need to find out the average grade of ten students instead.
So let me comment about this quote entirely.
Instead of doing it like this, let's use a multidimensional array, let's call it students.
Now I'm going to declare the areas land first, there will be two students, so the areas should be
two or not.
I'm going to start fallowed six to four areas with three elements in this area.
So now I'm going to type three floors, six to four here.
Now I need to give it a rest.
Here are the grades of the first student and here are the second students grades, then I'm going to
sum all the grades by hand like this.
Let's do that for the first student.
First, I'm going to get the first student from the altar of students like this.
This returns the first error.
Then let's get the grades of the first student by using the returned array.
Then let's get the second and the third grades of the first student.
OK.
And lastly, let's do the same thing for the second student.
OK, this time index is one, so it returns the second student's grace.
OK, now let's calculate the total number of grades again.
Let's first convert it to offload 64.
Then here I'm going to get the total number of students first.
These returns two, because there are two inner errors in the students.
OK, then I'm going to multiply this with the total number of grades for the first student like this
since all the inner arrays have the same length.
So using the first student here is enough.
I could have used the second student as well.
Doesn't matter.
All right, now let's print the average grade like this.
All right, let me read on it.
The result is the same cool now you know how to get the elements from a multidimensional array.
However, this isn't good either.
Now let's do it for the last time in the best way possible.
So now let me duplicate this quote first and let me comment about this previous quote here, OK?
As you learn, you don't need to type the types here.
Go knows about it already from the terrorist elements.
So now I'm going to remove them altogether.
I also don't need to describe the areas that go can also find it on its own.
So now I'm going to change it to the ellipses like this.
All right.
Better than I'm going to delete this quote here.
They are not necessary anymore.
You're going to see it in a second, why here?
I'm going to range over.
The students are like this.
So this great variable is going to store each one of the inner arrays.
I need to sum all the grades, so I need another loop here.
Now, I'm going to range over this great variable like this.
You know, its type is three floors, six to far right, so its doors and Internet.
Now I'm going to add the great variable to the some variable here like this.
All right, Don, let's turn it now.
Cool, it still works and the result is correct.
All right, that's all for now.
See in the next picture, bye bye.