Golang builtin.make() function example

package builtin

The make built-in function allocates and initializes an object of type slice, map, or chan (only). Like new, the first argument is a type, not a value. Unlike new, make's return type is the same as the type of its argument, not a pointer to it.

Golang builtin.make() function usage example

 package main

 import "fmt"

 type Person struct {
 Age int
 }

 var personmap map[string]Person 

 func main() {
 personmap = make(map[string]Person)  // initializes the person object 

 personmap["Adam"] = Person{36}

 fmt.Println("Before delete : ", personmap)

 delete(personmap, "Adam")

 fmt.Println("After delete : ", personmap)

 }

Advertisement