Skip to content

Instantly share code, notes, and snippets.

@hiepndd
Created May 30, 2019 10:21
Show Gist options
  • Save hiepndd/0c70d64bf7a2c4aeffb34af08bee61e2 to your computer and use it in GitHub Desktop.
Save hiepndd/0c70d64bf7a2c4aeffb34af08bee61e2 to your computer and use it in GitHub Desktop.
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