PRACTICE / UNDERSTAND / REPEAT

Go: Slices & arrays

Practice slices & arrays with self-contained questions. Check your answer, then use the explanation to understand the reasoning.

60 questionsAnswers explainedFree · no login
Question 1 of 60
Slices & arrays · MCQQuestion link ↗

What does this Go slice length print?

values := []int{1, 2}
values = append(values, 3)
fmt.Println(len(values))
Choose one answer
Answer & explanation

Answer: 3

append returns a slice containing the original elements and the appended element.