package main import ( "fmt" ) func f1(slice []int) []int { slice[0] = 10 return slice } func f2(slice []int) []int { slice = append(slice, 4) slice[0] = 10 return slice } func f3(slice []int) []int { s := make([]int, len(slice)) copy(s, slice) s[0] = 10 return s } func main() { fmt.Println("f1") s := []int{1, 2, 3} fmt.Println(f1(s)) fmt.Println(s) fmt.Println("f2") s = []int{1, 2, 3} fmt.Println(f2(s)) fmt.Println(s) fmt.Println("f3") s = []int{1, 2, 3} fmt.Println(f3(s)) fmt.Println(s) } //-> f1 //-> [10 2 3] //-> [10 2 3] //-> f2 //-> [10 2 3 4] //-> [1 2 3] //-> f3 //-> [10 2 3] //-> [1 2 3]