点击运行
package main import ( "fmt" ) func subtactOne(numbers []int) { for i := range numbers { numbers[i] -= 2 } } func main() { nos := []int{8, 7, 6} fmt.Println("函数调用之前的slice: ", nos) subtactOne(nos) // 函数修改slice fmt.Println("函数调用之后的slice: ", nos) // 切片的修改在函数外部是可见的 }
运行结果 :
正在执行...