Welcome in his lecture, I'm going to talk about what an array is.
Let's get started.
Think of this grid like the computer memory.
OK, it has a lot of memory cells, which depends on the total capacity of your computer's memory.
Now you're looking at an empty memory segment which doesn't store any value yet.
Here, these diagonal lines are representing the memory cells, for example, one of them starts at
this memory location and and at this memory location.
By the way, not that each memory cell can only contain a value of one bite at most.
We had talked about this earlier, but let me make you remember again.
So when you declare a variable, go is going to store it in computer memory.
Right.
So here is about variable.
And here is another one.
As you can see, gold can allocate variables in different memory locations, right?
For example, here go allocates the first variable in the hundredth memory cell and the second variable,
five cells away from the first one in the one hundred and fifty memory cell.
Now, let's see how those stories and error in the memory in computer memory and empty array value looks
like this.
As you can see, an array is a collection type that can store multiple values and unlike variables,
Gobstoppers array elements in contiguous memory locations.
For example, the first element is in the hundredth memory cell and the second element is in the one
hundred first memory cell.
Together, all of these values represent a single era value.
So there is only one value here, actually, and through that you can access to its inner values.
So what is the importance of this?
Why this is a useful thing?
It is because, for example, let's say you are passing a binary file format in there.
You would need to represent the exact memory layout as that file format.
Or let's say you need to store a low level data structure in memory as exactly as it is, so you can
use an array to do so because an array is a direct representation of memory.
This memory layout also allows Gore to store and fetch elements in a very fast manner because each element
is right next to each other.
So CPU can cache some part of it and then it can work faster.
We won't go into details for these kind of stuff yet, but we'll take a look at these later on the course.
Each element of this array is one by thread, so this error is total size is too wise because the size
of an error is equal to the total size of all its elements.
So go allocated to Biso memory block for this array.
He resigned in 16 hours with two elements and let's say the first element is located in the underground
memorizer, then the second element should have to be located in the 100 second memory cell.
Right next to the previous value is because this time each element occupies two bytes.
So these arrays, total size is for whites.
Now, let's talk about Habanera Syntax works.
This number represents these areas.
OK, so this area can only store two elements at most.
You can also use constant expressions when declaring the land of an era, for example, here, this
area is Lancs is still too, by the way, Google calculates this value at the compile time.
Let me explain.
As you know, you can change a variables type wants to declare it right.
It is the same for iRace since the land of an era also belongs to its type.
It has to be a constant value and error is Langguth determines how many elements that you can store
in an array it determines is fixed capacity.
So once you set its length, you cannot change it.
Later it becomes fixed.
However, if you need a bigger array, you can declare a new one like this.
Here for this array go resource three bytes of memory.
However, if the elements were an entry to the world reserve twelve bytes of memory instead.
Here is another example for this array.
Gold reserves five bytes of memory because its length is five.
And lastly, you cannot set an erase linked to a negative number because doing so is meaningless, right?
OK, let's get back to our two elements right now, let's talk about the types and erase element type
determines what type of values that you can store in that area.
OK.
For example, here, this area is type in the indicates that it can only store two elements.
Remember, when you declare a variable without an initial value, it gets a zero value, right?
It is the same with the error elements.
So when you don't initialize the error elements, Gogu sets them to their zero values depending on the
error element type.
For example, here these errors elements are not initialized yet.
Right.
And because of these areas, element type is byte, which is a numeric type.
So Gazette's all its elements of the array, two zeros automatically.
By the way, you can use any type as the element type for an array.
For example, here is a new era which can only store string values.
Here, Thisara stores two empty string values because they haven't been initialized yet.
OK.
As I said, you can create an array with any element type, however, you cannot change its elements
to another time once you declare it's OK.
OK, now let's take a look at this example here.
I'm trying to store and numeric value in this area, but I cannot do this because this OIRA's element
type is now a string.
All right, let's return to our byte array again now I'm going to show you how to access and change
these areas elements, by the way, you can do so because each element of an array is an unnamed variable,
so you can use them as variables.
If it wasn't like that, then you wouldn't be able to access individual elements.
Do you wonder why?
It's because God doesn't allow you to access arbitrary memory locations by default.
However, you can do so by using some dark magic, which is, by the way, not the best time to talk
about it yet.
So because God doesn't allow you to access arbitrary memory locations so you can get the individual
elements from an array just by directly accessing the memory location.
So instead of that go prolacta, another mechanism called index expressions, as you know.
So through them you can access the array elements.
All right.
As you can see here, there are two bytes variable stored in this area right now.
Let's learn how to work with them.
Let's get the first element at index zero.
Now, let's get the last element at index one.
Wow, that was easy.
OK, now let's find out the land of this area by using the built in land function like this, it returns
to because there are two elements in this area.
OK, now let's see what we can do.
For example, let's try to get an element at indexed to this doesn't work because the index should be
less than the length of the array.
Right.
Because the goal indexes start at zero.
Now let's try to get an element in the minus one index.
This doesn't work either because the index should be greater than or equal to zero.
OK, let me show you an example here.
I'm going to assign a value to the first element like this, so the first element becomes six.
Now I'm going to subtract three from the second elements like this.
So the second element becomes minus three, as you can see, when I get on elements, it acts like a
variable or I wouldn't be able to assign to it.
You can only use assignment operators when the left hand side is something that is stored in memory.
Let me show you one more example.
Now I'm going to assign a Sprink value to the first element.
As you can see, I cannot do this, can I?
Here is a string value, but these arrays element type is int.
So there is a type mismatch here.
That's why I couldn't assign a string value to this entry.
All right.
That's all for now.
You learned a lot of useful knowledge about race.
Now, let's take a quick break here.
And in the next lecture, I'm going to show you examples in the coding, Ed..
See you there, Babbo.