Created
March 1, 2015 22:17
-
-
Save cevaris/d24d97f07a2ec638fa0f to your computer and use it in GitHub Desktop.
Golang Pointers
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 | |
// Run this in playground | |
// https://play.golang.org/p/k47thicjzn | |
import "fmt" | |
type Item struct { | |
a *Item | |
b string | |
} | |
func main() { | |
var i *Item = &Item{a:&Item{}, b:"pointer"} | |
var j *Item = i | |
fmt.Printf("%v %v %p %p %v\n", i, j, i, j, i==j) | |
i.b = "hell!!" | |
fmt.Printf("%v %v %p %p %v\n", i, j, i, j, i==j) | |
i.a = i | |
fmt.Printf("%v %v %p %p %v\n", i, j, i, j, i==j) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output
Source: How do I print the pointer value of a Go object? What does the pointer value mean?