Recall & Review
beginner
What is an array in Go?
An array in Go is a fixed-size collection of elements of the same type, stored in contiguous memory locations.
Click to reveal answer
beginner
How do you access the first element of an array named
arr in Go?You access it using
arr[0] because Go arrays are zero-indexed, meaning the first element is at index 0.Click to reveal answer
intermediate
What happens if you try to access an array element with an index out of range in Go?
Go will cause a runtime panic with an 'index out of range' error, stopping the program.
Click to reveal answer
beginner
Given
var arr = [3]int{10, 20, 30}, what is the value of arr[2]?The value is 30, because array indices start at 0, so
arr[2] is the third element.Click to reveal answer
beginner
Can you change the value of an element in a Go array after it is created?
Yes, you can assign a new value to an element by accessing it with its index, like
arr[1] = 50.Click to reveal answer
What is the index of the first element in a Go array?
✗ Incorrect
Go arrays start indexing at 0, so the first element is at index 0.
How do you access the third element of an array named
nums?✗ Incorrect
Since indexing starts at 0, the third element is at index 2.
What happens if you try to access
arr[5] in an array of length 3?✗ Incorrect
Accessing an index outside the array length causes a runtime panic in Go.
Can you assign a new value to an existing element in a Go array?
✗ Incorrect
Go arrays allow changing element values by accessing them with their index.
Which of these is a valid way to declare an array of 4 integers in Go?
✗ Incorrect
Option C declares a fixed-size array of 4 integers. Options B and D declare slices, and C has fewer elements than size.
Explain how to access and modify elements in a Go array.
Think about how you get and set values using the index.
You got /4 concepts.
Describe what happens if you try to access an array element outside its range in Go.
What does Go do to protect you from invalid access?
You got /4 concepts.