Skip to content

Instantly share code, notes, and snippets.

@pzurek
Last active December 23, 2015 14:09
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 pzurek/6646652 to your computer and use it in GitHub Desktop.
Save pzurek/6646652 to your computer and use it in GitHub Desktop.
Pointers in Go. Short tale of asterisk and ampersand.
package main
import "fmt"
func main() {
var a int
var b int
var c *int
a = 42
b = a
c = &a
fmt.Printf("Values:\n a = %v\n b = %v\n c = %v\n*c = %v\n", a, b, c, *c)
a = 21
fmt.Printf("Values:\n a = %v\n b = %v\n c = %v\n*c = %v\n", a, b, c, *c)
fmt.Printf("Types:\n a: %T\n b: %T\n c: %T\n*c: %T\n", a, b, c, *c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment