Complete the code to declare a slice of integers.
var numbers [1]In Go, slices are declared using [] followed by the type, like []int for a slice of integers.
Complete the code to create a slice from an array.
arr := [5]int{1, 2, 3, 4, 5} slice := arr[1]
To create a slice from an array, use the slice expression with start and end indices like arr[1:4].
Fix the error in the code to append an element to a slice.
var s []int
s = append(s, [1])The append function adds an integer value to the slice. The value must be an int, not a string.
Fill both blanks to create a slice with make and set its length.
s := make([1], [2])
The make function creates a slice of type []int with length 5.
Fill all three blanks to create a slice from an array and append a value.
arr := [4]int{1, 2, 3, 4} s := arr[1] length := len(s) + [3] s = append(s, [2])
The slice s is created from arr[1:3], then 5 is appended. The length is increased by 1 after append.
