golang append() evaluated but not used

后端 未结 5 1344
失恋的感觉
失恋的感觉 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:27

    sliceA =append(sliceA, 4) append returns a slice containing one or more new values. Note that we need to accept a return value from append as we may get a new slice value.

提交回复
热议问题