POINTERS
This commit is contained in:
parent
49b436d6f9
commit
7a51de11e4
3
structs/go.mod
Normal file
3
structs/go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module lovelynet.net/structs
|
||||||
|
|
||||||
|
go 1.17
|
||||||
36
structs/main.go
Normal file
36
structs/main.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type contactInfo struct {
|
||||||
|
email string
|
||||||
|
zipCode int
|
||||||
|
}
|
||||||
|
|
||||||
|
type person struct {
|
||||||
|
firstName string
|
||||||
|
lastName string
|
||||||
|
contactInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
jim := person{
|
||||||
|
firstName: "Jim",
|
||||||
|
lastName: "Party",
|
||||||
|
contactInfo: contactInfo{
|
||||||
|
email: "jim@gmail.com",
|
||||||
|
zipCode: 3177,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
jim.updateName("test")
|
||||||
|
jim.print()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pointerToPerson *person) updateName(name string) {
|
||||||
|
(*pointerToPerson).firstName = name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p person) print() {
|
||||||
|
fmt.Printf("%+v\n", p)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user