+ 10

Problem with a challenge question!!

Why is only the x incremented, and the y and the z not?? https://code.sololearn.com/cOc3EnZP166w/?ref=app

4th Jan 2018, 2:06 AM
Prop de Puppy
Prop de Puppy - avatar
5 Answers
+ 8
i am just a beginner..but i think on "logical OR || since first is true whether second condition is true or false..it will be true..so it skipped y and z part..here x is pre incremented (++x) so value of x is 2..but y and z value becomes same i.e 1.
4th Jan 2018, 2:40 AM
Sunil Thakali
Sunil Thakali - avatar
+ 8
Thank you, evaluating from left to right the expression (++x || ++y && ++z) because of short circuit evaluation only ++x is evaluated, it gives true to the logic operator OR and AND expressions!!
4th Jan 2018, 4:40 AM
Prop de Puppy
Prop de Puppy - avatar
+ 6
check this code out the comments will tells u 👍 https://code.sololearn.com/ciMCHtM5eAPe/?ref=app
12th Jan 2018, 2:15 AM
AmÂČar YasÂČer
AmÂČar YasÂČer - avatar
+ 5
Try changing to && it will check 2nd condition and y and z value will be 2,2
4th Jan 2018, 2:48 AM
Sunil Thakali
Sunil Thakali - avatar
+ 1
pre increment in cout statement usually behaves wierdly, its compiler dependent, try it in some other compiler, you will get a different answer
4th Jan 2018, 2:52 AM
‎ ‏‏‎Anonymous Guy