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

import "fmt"

type SampleStruct struct {
	Id int64
	Name string
}


func main() {
	v1 := SampleStruct{1, "taro"}
	fmt.Println(v1) // {Id:1 Name:taro}
	hoge(v1)
	// 値渡し
	fmt.Println(v1) // {Id:1 Name:taro}

	
	v2 := SampleStruct{ Name: "jiro" }
	fmt.Println(v2) // {0 jiro}
}

func hoge(v SampleStruct) {
	fmt.Println(v) // {Id:1 Name:taro}
	v.Id = 2
	fmt.Println(v) // {Id:2 Name:taro}
}