mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-10-27 00:31:41 +00:00
Fixes #205
This commit is contained in:
@@ -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函數都是返迴一個新的變量的地址,因此下面兩個地址是不同的:
|
||||
|
||||
Reference in New Issue
Block a user