函数参数传递过程中,数组是值传递的,切片是指针传递。
直接上代码:
package main
import "fmt"
func main() {
a := [3]int{0, 1, 2}
for i, v := range a {
if i == 0 {
a[1], a[2] = 999, 999
fmt.Println(a)
}
a[i] = v + 100
}
fmt.Println(a)
}
直接上代码:
package main
import "fmt"
func main() {
a := [3]int{0, 1, 2}
for i, v := range a {
if i == 0 {
a[1], a[2] = 999, 999
fmt.Println(a)
}
a[i] = v + 100
}
fmt.Println(a)
}