ADVERTISEMENT
ADVERTISEMENT

Golang true and false Constants with Examples

Golang | true and false Constants: Here, we are going to learn about the true and false constants with examples.
Submitted by IncludeHelp, on October 12, 2021

true and false Constants

In the Go programming language, true and false are the two untyped boolean values, these are boolean constants.

Syntax:

true
false

Parameter(s):

  • None

Return Value:

None

Example 1:

// Golang program to demonstrate the
// example of true and false constants

package main

import (
	"fmt"
)

func main() {
	// Printing the values and types
	// of true and false
	fmt.Printf("%T, %v\n", true, true)
	fmt.Printf("%T, %v\n", false, false)
}

Output:

bool, true
bool, false

Example 2:

// Golang program to demonstrate the
// example of true and false constants

package main

import (
	"fmt"
)

func main() {
	age := 21
	// Comparison of the expression
	if age >= 18 == true {
		fmt.Println("Eligible for voting")
	} else {
		fmt.Println("Not eligible for voting")
	}
}

Output:

Eligible for voting

Golang builtin Package »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.