gpt4 book ai didi

pointers - Golang中Structure变量中Field的访问地址

转载 作者:IT王子 更新时间:2023-10-29 02:32:28 25 4
gpt4 key购买 nike

如何访问 GOLANG 结构中 FIELD 的指针或地址。我有整个结构变量的地址或指针,但无法正确访问结构内部字段的地址。到目前为止,我已经尝试过 Reflection,但似乎在某个地方坏了。非常感谢任何帮助。

最佳答案

例如,

package main

import (
"fmt"
)

type S struct{ F1, F2 int }

func main() {
s := new(S)
f1, f2 := &s.F1, &s.F2
fmt.Printf("%p %p %p\n", s, f1, f2)
}

输出:

0x1040a128 0x1040a128 0x1040a12c

关于pointers - Golang中Structure变量中Field的访问地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44752447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com