go 指针
1、函数内传指针会改变原值
type A struct {
Age int
}
func main() {
a := &A{Age: 1}
Changed(*a)
fmt.Println(a) // &{1}
RealChanged(a)
fmt.Println(a) // &{999}
}
func Changed(a A) {
a.Age = 666
}
func RealChanged(a *A) {
a.Age = 999
}
type A struct {
Age int
}
func main() {
a := &A{Age: 1}
Changed(*a)
fmt.Println(a) // &{1}
RealChanged(a)
fmt.Println(a) // &{999}
}
func Changed(a A) {
a.Age = 666
}
func RealChanged(a *A) {
a.Age = 999
}