Back to questions
JuniorTheoryCommon
What does the program print?
package main
import "fmt"
func check() bool {
fmt.Print("check ")
return true
}
func main() {
fmt.Println(false && check())
}false
- Expecting
check false:&&stops as soon as its left side isfalse, socheck()is never called and prints nothing. - Expecting
truebecausecheck()returnstrue:&&istrueonly when both sides are, and the left side is alreadyfalse.
- What does the program print with
true && check()instead? - Is
checkcalled intrue || check(), and what is printed?