+ 2

Boolean Truth Table C++_How Does it Work?

Given the following code: int x = 1; int y = 2; int z = 3; Which of the following presents the how the evaluation is done? if ( (x == 2) || (y == 2) || (z == 2) ) 1. false or true or false false or false false 2. false or true or false false or false true 3. true or true or false true or false false 4. false or true or false true or false true

20th Aug 2017, 12:51 PM
gorgamin
gorgamin - avatar
3 ответов
+ 1
x==2 is false, y==2 is true, and z==2 is false again. So it's: false OR true OR false. Or-statements evaluate true if at least one factor is true, given by y==2. So the entire evaluation is true and the if-block will be executed.
20th Aug 2017, 1:17 PM
Shadow
Shadow - avatar
0
logical statement are a little different that classical operators a or ... will return true if a is true without testing the right part a and ... will return false if a is false without testing the right part so : 0 && call() will never do call neither do : 1 || call()
20th Aug 2017, 1:41 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
- 1
1- false or true or false will be true it is bcoz in between false and true the logic operator is OR which states that either of the operand is true the answer will be true.
21st Aug 2017, 2:35 PM
geeta joshi
geeta joshi - avatar