golang append() evaluated but not used

后端 未结 5 1336
失恋的感觉
失恋的感觉 2021-02-01 12:12
func main(){
     var array [10]int
     sliceA := array[0:5]
     append(sliceA, 4)
     fmt.Println(sliceA)
}

Error : append(sliceA, 4

5条回答
  •  执笔经年
    2021-02-01 12:30

    Per the Go docs:

    The resulting value of append is a slice containing all the elements of the original slice plus the provided values.

    So the return value of 'append', will contain your original slice with the appended portion.

提交回复
热议问题