package main
import (
log "github.com/sirupsen/logrus"
)
func printSlice(slice []int) {
slice[0] = 11
log.Infof("sli %o", slice)
}
func main() {
arr := [...]int{1, 2, 3, 4, 5, 6}
log.Infof("Arr out %o", arr)
slice := arr[3:]
printSlice(slice)
log.Infof("sli out %o", slice)
log.Infof("Arr out2 %o", arr)
}
其结果为何:
time="2024-03-12T11:38:44+09:00" level=info msg="Arr out [1 2 3 4 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="sli [13 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="sli out [13 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="Arr out2 [1 2 3 13 5 6]"
我认为,结果应当是:
time="2024-03-12T11:38:44+09:00" level=info msg="Arr out [1 2 3 4 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="sli [11 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="sli out [11 5 6]"
time="2024-03-12T11:38:44+09:00" level=info msg="Arr out2 [1 2 3 11 5 6]"
我的田地版本是1.18.10。