Connection Between Slices and Arrays
Explore how slices in Go are linked to underlying arrays, allowing modifications via slices to affect arrays. Understand how capacity changes can sever this connection and see practical examples demonstrating these behaviors.
We'll cover the following...
We'll cover the following...
How slices are connected to arrays
As mentioned before, behind the scenes, each slice is implemented using an underlying array. The length of the underlying array is the same as the capacity of the slice, and there exist pointers that connect the slice elements to the appropriate array elements.
We can understand that by connecting an existing array with a slice, Go allows us to reference an array or a part of an array using a slice. This has some strange capabilities, including the fact that the changes to the ...