Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marclambrichs/59899a38a9cb31fc60389a261c359f16 to your computer and use it in GitHub Desktop.
Save marclambrichs/59899a38a9cb31fc60389a261c359f16 to your computer and use it in GitHub Desktop.
using the & operator
// -*- mode:go;mode:go-playground -*-
// snippet of code @ 2018-05-07 14:35:38
// === Go Playground ===
// Execute the snippet with Ctl-Return
// Remove the snippet completely with its dir and all files M-x `go-playground-rm`
package main
import (
"fmt"
)
type someType struct {
ID int64
Name string
}
func main() {
// Create a pointer p, of type *someType, which points to an unnamed someType variable
v := someType{ID: 1, Name: "name1"}
p1 := &v.Name
fmt.Printf("name = %s\n", v.Name)
*p1 = "name2"
fmt.Printf("name = %s\n", v.Name)
p2 := &(v.Name)
fmt.Printf("name = %s\n", v.Name)
*p2 = "name3"
fmt.Printf("name = %s\n", v.Name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment