Created
October 11, 2019 23:29
-
-
Save mcncl/1dfc09dcb999820629720210981e92fa to your computer and use it in GitHub Desktop.
Golang Pointer Example
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
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