This is slightly modified code from slices
var buffer [256] byte
func SubtractOneFromLength(slice []byte) []byte {
slice = slice[0 : len(slice)-1]
return slice
}
func main() {
slice := buffer[10:20]
fmt.Println("Before: len(slice) =", len(slice))
newSlice := SubtractOneFromLength(slice)
fmt.Println("After: len(slice) =", len(slice))
fmt.Println("After: len(newSlice) =", len(newSlice))
newSlice2 := SubtractOneFromLength(newSlice)
fmt.Println("After: len(newSlice2) =", len(newSlice2))
}
It says that contents of a slice argument can be modified by a function, but its header cannot.
How can I print header of newSlice2 on my screen?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…