-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointer.go
41 lines (30 loc) · 860 Bytes
/
pointer.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
package main
import "fmt"
type Address struct {
City, Province, Country string
}
func ChangeCountryToIndonesia(address *Address) {
address.Country = "Indonesia"
}
func main() {
address1 := Address{City: "Semarang", Province: "Jateng", Country: "Indonesia"}
address2 := &address1
address3 := &address1
address2.City = "Kendal"
*address2 = Address{City: "Jakarta", Province: "DKI Jakarta", Country: "Indonesia"}
fmt.Println(address1)
fmt.Println(address2)
fmt.Println(address3)
var address4 *Address = new(Address)
address4.City = "Bandung"
// address4 = &Address{City: "Bandung"}
// var address4 *Address = &Address{City: "Bandung", Province: "Jabar", Country: "Indonesia"}
fmt.Println(address4)
alamat := Address{
City: "Solo",
Province: "Jateng",
Country: "",
}
ChangeCountryToIndonesia(&alamat)
fmt.Println(alamat)
}