Golang builtin.new() function example

package builtin

The new built-in function allocates memory. The first argument is a type, not a value, and the value returned is a pointer to a newly allocated zero value of that type.

Golang builtin.new() function usage example

 package main

 import "fmt"

 type Person struct {
 Age int
 }


 func main() {

 human := new(Person)

 human.Age = 36

 fmt.Println(human)
 }

Reference :

http://golang.org/pkg/builtin/#new

Advertisement