Intermediate Go (Golang)
Q50 / 100

What is the difference between a nil slice and an empty slice?

Correct! Well done.

Incorrect.

The correct answer is B) A nil slice has no backing array (len=0, cap=0, nil); an empty slice ([]int{}) has a backing array with zero elements

B

Correct Answer

A nil slice has no backing array (len=0, cap=0, nil); an empty slice ([]int{}) has a backing array with zero elements

Explanation

var s []int is nil (s == nil is true). s := []int{} or make([]int, 0) is empty (s == nil is false). Both have length 0 and can be appended to.

Progress
50/100