Quick actions

cmd+k|ctrl+k

Navigation

Languages

Essential Go / Pointers

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:01:13Z

Updated

2019-03-26T10:01:13Z

package main

import "fmt"

func main() {
	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)
}
INFO