func test(res [][]int) { res[0] = []int{2,2,2,2} res[1][0] = 3 } func main() { res := [][]int{[]int{1,1,1,1},[]int{2,2,2,2}} test(res) fmt.Printf("%#v",res) // out: [][]int{[]int{2, 2, 2, 2}, []int{3, 2, 2, 2}} }
func test(res [][]int) { res = append(res, []int{3,3,3,3}) res = append(res, []int{4,4,4,4}) } func main() { res := [][]int{[]int{1,1,1,1},[]int{2,2,2,2}} test(res) fmt.Printf("%#v",res) // out: [][]int{[]int{1, 1, 1, 1}, []int{2, 2, 2, 2}} }
原文:https://www.cnblogs.com/binHome/p/12862453.html