Recall & Review
beginner
What is a slice in Go?
A slice in Go is a flexible, dynamic view into the elements of an array. It does not store data itself but references an underlying array.
Click to reveal answer
beginner
How does a slice relate to its underlying array?
A slice points to a segment of an array. Changes to the slice elements affect the underlying array and vice versa.
Click to reveal answer
intermediate
What happens when you append to a slice that has no extra capacity?
Go creates a new underlying array with more capacity, copies the old elements, and appends the new ones. The slice then points to this new array.
Click to reveal answer
beginner
How can you create a slice from an array?
You can create a slice by specifying a range of indices on an array, like:
slice := array[start:end].Click to reveal answer
beginner
Does modifying a slice affect the original array?
Yes, because the slice references the original array's elements, modifying the slice changes the array's data.
Click to reveal answer
What does a Go slice store internally?
✗ Incorrect
A slice stores a pointer to the underlying array, its length, and its capacity.
If you change an element in a slice, what happens to the underlying array?
✗ Incorrect
Slices reference the array, so changes to the slice affect the array.
What happens when you append to a slice that has enough capacity?
✗ Incorrect
If capacity allows, append adds elements to the existing array without creating a new one.
How do you create a slice from an array named 'arr' from index 2 to 5?
✗ Incorrect
The slice syntax includes the start index and excludes the end index, so arr[2:5] includes indices 2,3,4.
Which of these is true about slices in Go?
✗ Incorrect
Slices can grow by allocating a new underlying array when capacity is exceeded.
Explain how a slice and its underlying array are connected in Go.
Think about how slices are views into arrays.
You got /4 concepts.
Describe what happens internally when you append an element to a slice that has no remaining capacity.
Consider slice capacity and memory allocation.
You got /4 concepts.