Skip to content

Instantly share code, notes, and snippets.

@chardos
Last active January 22, 2019 23:55
Show Gist options
  • Save chardos/4472e9c0c7df6811cfba687c192c9835 to your computer and use it in GitHub Desktop.
Save chardos/4472e9c0c7df6811cfba687c192c9835 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
a := 10
b := &a // &a is the reference of a
c := a
fmt.Println(a, b, *b, c) // *b means the value this reference is pointing to (dereference the value)
// 10 0xc0000160a0 10 10
a = 20
fmt.Println(a, b, *b, c)
*b = 30
fmt.Println(a, b, *b, c)
// 30 0xc0000160a0 30 10
c = 40
fmt.Println(a, b, *b, c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment