0

Explain this Please. Why answer is 1211? (C++)

#include <iostream> using namespace std; int main() { int x=1,y=1,z=1; cout <<(++x||++y&&++z); cout <<x<<y<<z; } answer: 1211

7th Jan 2018, 8:20 PM
Jamol Makhsudov
Jamol Makhsudov - avatar
3 Réponses
+ 3
because of the || or. It is finding no reason not to perform your first operation. change || to && also and watch then. Remember it won't make a choice just because you said ||. it will still use the first valid operation it will not randomly decide to evaluate ++y and skip ++× on its own.
7th Jan 2018, 9:09 PM
emmey
emmey - avatar
7th Jan 2018, 8:40 PM
I. Stark
I. Stark - avatar
0
Thanks for answer. Question is why y and z is not increesing? Why answer is not 1222?
7th Jan 2018, 8:44 PM
Jamol Makhsudov
Jamol Makhsudov - avatar