Menu Close

Go – Program to check bool variable contains true or false in go

Here, we will see program to check bool variable contains true or false value in go. We will also see how to use bool in program with example.

Zero value of bool variable in go is false.

Code:

package main

import (

  "fmt"

)

func main() {

  var n bool = false

  if n == false{

    fmt.Println("Contains zero value: ", n)

  } else {

    fmt.Println("Does not contains zero value: ", n)

  }



  n = true

  if n == false{

    fmt.Println("Contains zero value: ", n)

  } else {

    fmt.Println("Does not contains zero value: ", n)

  }

}

Output:

Contains zero value: false

Does not contains zero value: true

To learn more about golang. Please follow given below link.

https://techieindoor.com/go-lang/

References:

https://golang.org/doc/
https://golang.org/pkg/

Posted in golang, golang program

Leave a Reply

Your email address will not be published. Required fields are marked *