dongqiongzheng0615 2019-05-13 08:07
浏览 133
已采纳

当我:=&b时,“&i”是什么意思

I'm learning the go, I tried the '&' to get the memory address.But I werid that what's the meaning of '&i',and 'i' came from i := &b , b is a int.

b := 7
i := &b
fmt.Println(&b) //print => 0xc000088000
fmt.Println(i) //print => 0xc000088000
fmt.Println(&i) //print => 0xc00000e018

In this case , What's the meaning of '&i'?

  • 写回答

3条回答 默认 最新

  • dousong4777 2019-05-13 08:26
    关注

    & is the address operator, evaluating it results in a memory address, which when passed to the fmt package, usually the memory address is printed in hexadecimal format ("base 16 notation, with leading 0x").

    A memory address is just that: a memory address. It doesn't matter if it's an address of an int variable or a string, or a variable of a pointer type. When printed, they all look the "same".

    The address operator:

    For an operand x of type T, the address operation &x generates a pointer of type *T to x.

    So the address operator gives you a pointer value which when you dereference, you get back the original value.

    &b will be an address of the variable b, of type *int, which when you dereference: *b will give you (the value of) b.

    &i will be the address of the variable i, of type **int, which when you dereference: *i will give you the value of i which is the address of b. So if you also dereference that: **(&i), that will also give you (the value of) b.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容