Created
May 30, 2019 10:21
-
-
Save hiepndd/0c70d64bf7a2c4aeffb34af08bee61e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func double(x *int) { | |
*x += *x | |
x = nil // the line is just for explanation purpose | |
} | |
func main() { | |
var a = 3 | |
double(&a) | |
fmt.Println(a) // 6 | |
p := &a | |
double(p) | |
fmt.Println(a, p == nil) // 12 false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment