Zero Values and new
Variables without a value get a zero value: 0, an empty string, false or nil. new(T) returns a pointer to a zero T.
Example
var i int
var s string
var b bool
var p *int
var sl []int
var m map[string]int
fmt.Println(i, s == "", b, p == nil, sl == nil, m == nil)
q := new(int)
*q = 7
fmt.Println(*q)Result
0 true false true true true 7
Exercise
Zero value of a pointer.
var p *int // p == Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.