[[Go]]は[[値渡し]]。[[仮引数]]にいかなる操作をしても[[実引数]]には影響がない。
> [!warning]
> [[Goのスライスは参照の値渡し]]なので注意
```go
package main
import "fmt"
type Coordinate struct {
x int
y int
}
func destroyArgString(x string) {
x = "wriiiiiiiiiiiiiiiiiii"
}
func destroyArgStruct(s Coordinate) {
s = Coordinate{
x: 65535,
y: 65535,
}
}
func destroyArgStructReference(s Coordinate) {
s.x = 65535
s.y = 65535
}
func main() {
x := "init"
destroyArgString(x)
fmt.Println(x)
// init
s1 := Coordinate{
x: 0,
y: 0,
}
destroyArgStruct(s1)
fmt.Println(s1)
// {0 0}
s2 := Coordinate{
x: 0,
y: 0,
}
destroyArgStructReference(s2)
fmt.Println(s2)
// {0 0}
}
```
<button class="playground"><a href="https://go.dev/play/p/SNGHTUyOtVb">Playground</a></button>