comparison between map initialization

tags: learning go programming diff-between

content

var m map[int]int

  • returns map[int]int
  • value of m is nil (nil map)
  • readable, not writable, m[1] = 1 gives error m =: new(map[int]int)
  • returns *map[int]int, it’s a pointer
  • value of m is the address of a nil map
  • readable, not writeable m =: make(map[int]int)
  • returns map[int]int, not a pointer
  • value of m is an empty map, NOT a nil map
  • readable, writable. m[1] = 1 works

up

down

reference