Why is this code outputting 2? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is this code outputting 2?

I'm feeling dumb, I do not know why it's 2. https://code.sololearn.com/cYvA09ScIcFC/?ref=app

24th Jul 2017, 7:21 AM
Jonas Schröter
Jonas Schröter - avatar
2 Answers
+ 10
a=1,b=2 => a++ == b a == b (false) a++ (a=2) => In expr1 && expr2, expr2 won't be checked if expr1 is false. => b i.e. 2 is printed.
24th Jul 2017, 7:33 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 2
*facepalm* Thank you so much 😊.
24th Jul 2017, 8:00 AM
Jonas Schröter
Jonas Schröter - avatar