Skip to content

Instantly share code, notes, and snippets.

@mcncl
Created October 11, 2019 23:29
Show Gist options
  • Save mcncl/1dfc09dcb999820629720210981e92fa to your computer and use it in GitHub Desktop.
Save mcncl/1dfc09dcb999820629720210981e92fa to your computer and use it in GitHub Desktop.
Golang Pointer Example
package main
import "fmt"
type house struct {
occupant string
}
func (houseLocation *house) changeTenant(newTenant string) {
(*houseLocation).occupant = newTenant
}
func main() {
myHouse := house{occupant: "Ben"}
fmt.Printf("The tenant is: %v \n", myHouse)
houseAddress := &myHouse
fmt.Println("Changing tenant.....")
houseAddress.changeTenant("Paul")
fmt.Printf("The tenant is: %v \n", myHouse)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment