Why You Can't Take the Address of a Map Value in Go

Map lookups in Go return value copies, not references, so you must use pointer types or reassign values to modify map data.

You cannot take the address of a map value because map lookups return a copy of the value, not a reference to the stored data. To modify a map value in place, you must store the address of the value in the map itself by using a pointer type as the map's value type.

m := make(map[string]*int)
val := 42
m["key"] = &val
*m["key"] = 100 // Modifies the value in place

If you need to modify a value retrieved from a map with a non-pointer type, you must reassign it back to the map.

m := make(map[string]int)
m["key"] = 42
m["key"] = m["key"] + 100 // Reassigns the updated copy