gpt4 book ai didi

pointers - 如何通过 Go 中的 map 指针更改/访问 map 实例的值?

转载 作者:数据小太阳 更新时间:2023-10-29 03:38:29 25 4
gpt4 key购买 nike

假设我们有代码:

var Cache_map *map[string]int

Cache_map = new(map[string]int)

那我们要在Cache_map中加入key: type & value 1,怎么办?

最佳答案

在这种情况下不需要newmake 或映射指针。骨架/示例:

package main

import "fmt"

var CacheMap = map[string]int{}

func main() {
CacheMap["type"] = 1
fmt.Printf("%#v\n", CacheMap)
}

Playground


输出:

map[string]int{"type":1}

关于pointers - 如何通过 Go 中的 map 指针更改/访问 map 实例的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16054855/

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