Menu Close

Go – Program to check the integer variable contains zero value or not in go

Here, we will see Program to check the integer variable contains zero value or not in go. Given below, you can find algorithm and program.

Zero value of integer variable in go is 0.

Code:

package main

import (

  "fmt"

)

func main() {

  var n int = 0

  if n == 0{

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

  } else {

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

  }



  n = 10

  if n == 0{

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

  } else {

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

  }

}

Output:

Contains zero value: 0

Does not contains zero value: 10

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 *