POINTERS
This commit is contained in:
1 parent
49b436d6f9
commit
7a51de11e4
2 files changed
+39
No files matched your search
@@ -0,0 +1,3 @@
|
||||
module lovelynet.net/structs
|
||||
|
||||
go 1.17
|
||||
@@ -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)
|
||||
}
|
||||
Reference in new issue
Block a user