Newer
Older
01_hello / struct / struct2.go
yhornisse on 25 Sep 2021 506 bytes add struct sample
package main

import "fmt"

type SampleStruct struct {
	Id int64
	Name, Address string
}


func main() {
	v1 := SampleStruct{1, "taro", "address"}
	fmt.Println(v1) // {Id:1 Name:taro Address:address}

	v2 := SampleStruct{1, "taro", "address"}
	v3 := SampleStruct{1, "jiro", "address"}
	fmt.Println(v1 == v2) // true
	fmt.Println(v1 == v3) // false
	p1 := &v1
	fmt.Printf("%p\n", p1)
	(*p1).Id = 2
	fmt.Println(*p1) // {Id:2 Name:taro Address:address}
	fmt.Println(v1) // {Id:2 Name:taro Address:address}
}