Skip to content

Instantly share code, notes, and snippets.

@tio-iis
Created Apr 24, 2022
Embed
What would you like to do?
package main
import "fmt"
func main() {
//構造体を値として宣言する
//ataiUser := User{
// name: "tio",
//}
//fmt.Println(ataiUser.name)
//ChangeAtaiUser(ataiUser)
//fmt.Println(ataiUser.name)
//構造体をポインタとして宣言する
//pointerUser := &User{
// name: "tio",
//}
//fmt.Println(pointerUser.name)
//ChangePointerUser(pointerUser)
//fmt.Println(pointerUser.name)
//スライスを宣言する
//s := []string{"iis", "tio"}
//ChangeSlice(s)
//fmt.Println(s)
//mapを宣言する
m := map[string]string{"name": "tio"}
ChangeMap(m)
fmt.Println(m)
}
type User struct {
name string
}
//値渡し
func ChangeAtaiUser(u User) {
u.name = "iis"
}
//参照渡し
func ChangePointerUser(u *User) {
u.name = "iis"
}
func ChangeSlice(s []string) {
s[1] = "iis"
}
func ChangeMap(m map[string]string) {
m["name"] = "iis"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment