数组元素的Go地址

数组元素的Go地址,go,Go,如何获取Go中数组元素的地址?使用获取数组元素的地址。下面是一个例子: package main import "fmt" func main() { a := [5]int{1, 2, 3, 4, 5} p := &a[3] // p is the address of the fourth element fmt.Println(*p)// prints 4 fmt.Println(a) // prints [1 2 3 4 5]

如何获取Go中数组元素的地址?

使用获取数组元素的地址。下面是一个例子:

package main

import "fmt"

func main() {
    a := [5]int{1, 2, 3, 4, 5}
    p := &a[3]     // p is the address of the fourth element

    fmt.Println(*p)// prints 4
    fmt.Println(a) // prints [1 2 3 4 5]
    *p = 44        // use pointer to modify array element
    fmt.Println(a) // prints [1 2 3 44 5]

}

请注意,指针只能用于访问一个元素。无法从指针中添加或减去以访问其他元素。

内存地址或索引?内存地址。在C中,数组地址+索引是什么?我怀疑您是否可以向数组中添加额外的字符。数组的大小是固定的。我知道没有指针算法。但是我仍然需要这个地址来存储在另一个容器中。