+ 2

How is the output 84

Int x = 7, y=4; If(++x > 6 || ++ y <5) Cout<<x<<y; else Cout<<x*y;

14th May 2019, 5:22 AM
Arslan Iftikhar
Arslan Iftikhar - avatar
5 ответов
+ 7
x = 7 So the evaluation for `++x > 6` yields true, and simultaneously increased value of <x> to become 8. Logical OR operator returns and yet doesn't check successive operands when the first one evaluates to true, that's why `++y < 5` is not getting executed (value of <y> remains to be 4). Because `++x > 6` evaluates to true, the `if` statement executed the `if` block rather than the `else` block. Hth, cmiiw
14th May 2019, 5:40 AM
Ipang
+ 5
This is called short circuiting, where successive operands are not checked when the result of the OR is already true.
14th May 2019, 8:30 AM
Sonic
Sonic - avatar
+ 4
You're welcome 👍
14th May 2019, 5:46 AM
Ipang
+ 1
Thanks
14th May 2019, 5:42 AM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 1
++x = 8 ++y = 5 answer 84 (concat output) 🤔
15th May 2019, 2:36 PM
Sanjay Kamath
Sanjay Kamath - avatar