Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
fun check(): Boolean {
println("check")
return true
}
fun main() {
val ok = false && check()
println(ok)
}false
- Expecting
checkbeforefalse:&&stops as soon as its left side isfalse, because the result can no longer becometrue, socheck()is never called. - Expecting
truebecausecheck()returnstrue:&&givestrueonly when both sides aretrue, and onefalsemakes the whole resultfalse.
- What does the program print if the line becomes
val ok = true && check()? - What does
true || check()give, and ischeck()called?