package main
import "fmt"
func main() {
s := []string{"A", "B", "C"}
fmt.Printf(" 原始切片:%v \n",s)
sliceOpt(&s)
fmt.Printf("修改后切片:%v \n",s)
}
func sliceOpt(s *[]string) {
*s = append(*s, "D")
(*s)[0] = "E"
}
输出结果:
原始切片:[A B C]
修改后切片:[E B C D]
Process finished with the exit code 0