Welcome back.
In the last lecture, you have learned everything about how to compare a race.
Now in this lecture, I'm going to talk about what happens and then you assign an error to another area.
Let's get started.
I believe you remember Hipster's book collection from the previous lectures, now let's say you want
to create the same bookcase.
To do that, you can assign it to another variable.
And when you do so, God creates a new bookcase.
And all the elements inside of the original bookcase are copied into the new bookcase.
Let me show you this in the court to understand it better.
Here is the computer memory again, this time each memory represents eight bytes because the error that
I'm going to create is an entry.
OK, now I'm going to declare an error variable to store the capacity of the bookcase, such as this
one.
This creates a new era in computer memory.
Then I'm going to put this blue area into a new variable named Red like this.
As you can see, this is just a simple variable assignment.
So when I do so go allocates a new memory space for twenty four bytes like this is because each area
elements, the size is eight bytes here.
The size of the allocated memory depends on the size of the element type.
OK, so you assign an error to a variable or parse it to a function.
Go copy's all the elements from the original array to the new one, one element at a time.
It's because an array value contains all of its elements in a single array value.
Think about this operation for a second.
Let's say you have an array that contains one million elements.
You may realize that this copying operation can be very inefficient.
However, for smaller arrays, this won't be an issue.
OK, now I'm going to show you that these two arrays are actually two different areas.
I mean, they are equal, but they are different.
It's because they are in different locations in the computer memory.
Now, I'm going to assign 10 to the first element of the blue array is updates the first element like
this.
Did you notice that the red area is still the same?
This is because it's a new era, Gore has allocated it in another memory location, they are separate,
different eras, changing one of them won't be reflected in the new one.
Let me show you one more example.
Now, I'm going to create the reader from scratch with a different type this time like this.
And interact with two elements.
Now I'm going to assign the blue array to the red array like this.
What do you think it is going to work?
Nope, it doesn't work is because these areas have different types.
So in summary, you can only assign race with identical types, OK?
Let me show you a few examples in coding, Ed.
Hipsters Love Bookstore has released three books last year, let's first create a three elements Trinko
like this.
Now, let's print the books.
OK, let me run it.
All right, so far, so good.
Now they want to release the new editions of the books for this year, so now I need to add second edition
for each book.
So I'm going to use a range class to get the indexes like this.
Now, I'm going to get the book at this index, then I'm going to add this second addition value to
this book.
All right, ready?
Let's run it.
Good, we have updated all the books, however, they want to display the last year's books along with
this year's best books, so I need to create a copy of the prayer.
Right, let's do that.
So I'm going to create a new era here, then I'm going to assign the primary to this one.
OK, I'm not done yet.
I also need to change this variable here to the book's variable.
It's because I only want to update the books are not depressed.
OK.
All right.
Let me print the books.
All right, let me run again now, notice that Provera didn't change only the books Erra has changed.
This is because when now assigned Pereiro to books, Eryr Go has allocated a new array.
Then it has copied all the elements of the primary to books so they are not connected.
Changing one of them does not affect the other one.
OK, Hipster's LE Bookstore has a new request.
They have changed their minds and now they want to release four books this year.
But the bookseller can only store three books because I have copied it from the primary.
Right, so they have the same length, which is three.
So I need to create a new speaker with four elements.
Right.
So I'm going to remove this declaration first, then I'm going to declare and era with four elements
like this.
OK, good.
Let me read it again.
The book is empty, of course, because it's a new era that I've created from scratch.
Right.
So I need to copy the books into it from the primary.
Right.
Let's do that.
Let me first try to assign the primary to Boukhari.
As you can see, it doesn't work there.
Types are different.
So what should I do?
I need to copy the books manually, of course, so now I'm going to get the book title from the primary.
All I need to do is to add an iteration variable to this range expression like this so it will get the
next book from the primary.
Now, let's add this be variable just before this value.
Now, now it works.
Cool.
The book store owners also told me that the title of the next book that they are going to release this
year is Awesomes.
That's added as a.
All right, let's try it again, cool, it works.
All right, that's all for now.
Thank you for watching so far, seeing the next picture.