-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 1003 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import "fmt"
type contactInfo struct {
email string
zip int
}
type person struct {
firstName string
lastName string
contact contactInfo
}
func main() {
// diff way of declaring struct
//sanjeev := person{"Sanjeev", "Choubey"}
// sanjeev := person{firstName: "Sanjeev", lastName: "Choubey"}
// var sanjeev person
// sanjeev.firstName = "Sanjeev"
// sanjeev.lastName = "Choubey"
// fmt.Println(sanjeev)
// fmt.Printf("%+v", sanjeev)
sanjeev := person{
firstName: "Sanjeev",
lastName: "Choubey",
contact: contactInfo{
email: "[email protected]",
zip: 560037,
},
}
// pass by value
//sanjeev.updateFirstname("SANJEEV")
// Pass by refrence
sanjeevaddr := &sanjeev
sanjeevaddr.updateFirstname("SANJEEV")
sanjeev.print()
}
func (pointerToperson *person) updateFirstname(newfirstname string) {
(*pointerToperson).firstName = newfirstname
}
func (p person) print() {
fmt.Printf("%+v", p)
}