在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、代码 2、运行 1 package main 2 3 import "fmt" 4 5 func testValue(){ 6 fmt.Println("for value") 7 var a = [3]int {1, 2, 3} 8 var b = a 9 b[1]++ 10 fmt.Println("a = ",a, "\nb = ", b) 11 } 12 13 func testReference() { 14 fmt.Println("for reference") 15 var a = [3]int {1, 2, 3} 16 var b = &a 17 b[1]++ 18 fmt.Println("a = ",a, "\nb = ", *b) 19 } 20 21 func main() { 22 testValue() 23 testReference() 24 } 2、运行 $ go run valueAndRreference.go for value a = [1 2 3] b = [1 3 3] for reference a = [1 3 3] b = [1 3 3]
|
请发表评论