+ 3

Why v has the value false instead of true ?

Question on solearn challenge https://code.sololearn.com/clZIYZKLeQZo/?ref=app

19th May 2021, 1:37 PM
alagammai uma
alagammai uma - avatar
6 odpowiedzi
+ 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.
19th May 2021, 1:52 PM
Soumik
Soumik - avatar
+ 2
Soumik [Busy] That means if block will never be executed?
19th May 2021, 2:04 PM
Atul [Inactive]
+ 2
19th May 2021, 2:56 PM
Atul [Inactive]
+ 1
19th May 2021, 1:53 PM
alagammai uma
alagammai uma - avatar
+ 1
Atul Yeah
19th May 2021, 2:36 PM
Soumik
Soumik - avatar
0
Soumik [Busy] s it won't execute
19th May 2021, 2:06 PM
alagammai uma
alagammai uma - avatar