Wednesday, 1 May 2019

Go Language: Default or zero value


Variables that are declared without initialization are assigned with zero values.

Zero value
a.   0 for numeric types,
b.   false for the boolean type, and
c.    "" (the empty string) for strings.

App.go
package main

import "fmt"

func main() {
 var i int
 var f float64

 var b bool

 var s string

 fmt.Println("i = ", i)
 fmt.Println("f = ", f)
 fmt.Println("b = ", b)
 fmt.Println("s = ", s)

}

Output
i =  0
f =  0
b =  false
s = 

Previous                                                 Next                                                 Home

No comments:

Post a Comment