+ 3
Why v has the value false instead of true ?
Question on solearn challenge https://code.sololearn.com/clZIYZKLeQZo/?ref=app
6 Antworten
+ 3
booelan v =
(true || !(!false)) ? false : true
= (true || !true) ? false : true
= (true || false) ? false : true
= true ? false : true
= false
The parameter of the if statement has the value false so it will not execute and control is transferred to else clause. Since value of v is false, (v == true) returns false and v = false.
The parameter of an if statement is an expression that returns a boolean value. So if(0 == 0) and if(true) mean the same thing as the expression (0 == 0) returns true.
+ 2
Soumik [Busy] That means if block will never be executed?
+ 2
Soumik [Busy] thanks
+ 1
Soumik [Busy] thanks
+ 1
Atul Yeah
0
Soumik [Busy] s it won't execute