This commit is contained in:
chai2010
2016-01-18 12:14:26 +08:00
parent e16eebfefa
commit 1a780a2a52
2 changed files with 18 additions and 9 deletions

View File

@@ -14,10 +14,14 @@ fmt.Println(*p) // "2"
下面的兩個newInt函數有着相同的行爲
```Go
func newInt() *int { func newInt() *int {
return new(int) var dummy int
} return &dummy
}
func newInt() *int {
return new(int)
}
func newInt() *int {
var dummy int
return &dummy
}
```
每次調用new函數都是返迴一個新的變量的地址因此下面兩個地址是不同的