package main
import "fmt"
func main() {
fmt.Println(changeVa(1))
a := 10
b := &a
fmt.Println(changeVa(a)) // output: 11
fmt.Println(changePtr(b)) //output: 11
// 只是值传递调用了,调用结束退出栈,所以不会改变a的实际值
changeVa(a)
fmt.Println(a) // output: 11
// 指针传递地址,所以改变了该地址上指向的值
changePtr(b)
fmt.Println(*b) // output: 12
}
func changeVa(a int) int {
a = a + 1
return a
}
func changePtr(a *int) int {
*a = *a + 1
return *a
}