golang中的指针和C/C++类似。
以学习C语言指针时常用的swap函数为例,如果不使用指针时,交换的是swap函数中局部变量的值,因此无法交换两个参数的值。
package main
import "fmt"
func swapTwo(lhs int, rhs int) {
fmt.Printf("typeof args = %T\n", lhs)
lhs, rhs = rhs, lhs
}
func main() {
a :=
golang中的指针和C/C++类似。
以学习C语言指针时常用的swap函数为例,如果不使用指针时,交换的是swap函数中局部变量的值,因此无法交换两个参数的值。
package main
import "fmt"
func swapTwo(lhs int, rhs int) {
fmt.Printf("typeof args = %T\n", lhs)
lhs, rhs = rhs, lhs
}
func main() {
a :=