gofor
已收录文章:2篇
-
看程序: package main import ( "fmt" "time" ) func main() { str := []string{"I","like","Golang"} for _, v := range str{ v += "good" } for k, v := range str{ fmt.Println(k, v) } time.Sleep(1e9) } 结果: 0 I 1 like 2 Golang247 收藏
-
for range的val不能直接修改 因为地址不同 package main import "fmt" func main() { x := make([]int, 3) x[0], x[1], x[2] = 1, 2, 3 for i, val := range x { fmt.Println(&x[i], "vs.", &val) } } //输出 0x416020 vs. 0x41602c 0x4251 收藏