Created
April 24, 2022 12:46
-
-
Save tio-iis/1277c96b602a294bb376281cf8ddd3bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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