Skip to content

Instantly share code, notes, and snippets.

@kjk
Created November 5, 2019 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjk/caaac781536be9e4dc0c2f6eab8bc196 to your computer and use it in GitHub Desktop.
Save kjk/caaac781536be9e4dc0c2f6eab8bc196 to your computer and use it in GitHub Desktop.
Pointers
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
v := 5
// pv is a pointer to v
pv := &v
fmt.Printf("v: %d, pv: %p\n", v, pv)
// we change the value of v via pv
*pv = 4
fmt.Printf("v: %d\n", v)
// two pointers to the same value have the same address
pv2 := &v
fmt.Printf("pv: %p, pv2: %p\n", pv, pv2)
// :show end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment