Created
November 5, 2019 09:12
-
-
Save kjk/caaac781536be9e4dc0c2f6eab8bc196 to your computer and use it in GitHub Desktop.
Pointers
This file contains 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
// :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