Essential Go Basic types  Suggest an edit

Booleans

f

Value of type bool can be true or false.

Zero value of bool is false.

var b bool = true
fmt.Printf("b is: '%v'\n", b)
b = false
fmt.Printf("b is: '%v'\n", b)
var b2 bool
fmt.Printf("zero value of bool is: '%v'\n", b2)
b is: 'true'
b is: 'false'
zero value of bool is: 'false'

Size of bool variable (e.g. when part of a struct) is 1 byte.

b := true
fmt.Printf("size of bool is: %d\n", unsafe.Sizeof(b))
size of bool is: 1
  ↑ ↓ to navigate     ↵ to select     Esc to close