2025-04-08 17:01:19 +08:00

22 lines
408 B
Go

package main
import "fmt"
func main() {
// 基本指针操作
a := 42
p := &a // 获取a的地址
fmt.Printf("a的值: %d, 地址: %p\n", a, p)
fmt.Printf("通过指针访问值: %d\n", *p)
// 通过指针修改值
*p = 100
fmt.Printf("修改后a的值: %d\n", a)
// 指针的指针
pp := &p
fmt.Printf("指针的指针: %p\n", pp)
fmt.Printf("通过指针的指针访问值: %d\n", **pp)
}