0
int a=-1; cout<<(a++&&1);
what is the output of this code? I need an explanation about this?
7 Respostas
+ 4
Jagadesh Ramesh, the other side is not zero. There is a postfic ++, this code increments a after calculating the expression in brackets. So it is actually (-1&&1), which is 1 (true), because all ints, except 0 are true.
And if we change this code to(++a&&1) this will be 0, because prefix ++ will first increment a, and then use the incremented value to calculate the expression.
+ 3
Jagadesh Ramesh
in c++ for booleans
1 ( or any number other than 0) is true
0 is false
https://code.sololearn.com/cBhiuiXQRo53/?ref=app
+ 2
Jagadesh Ramesh
well && operators check if true or false.
unless there is one or two false values it will be true.
+ 2
thank you so much guys. I got it.
+ 1
Output:
1
+ 1
but using this && operator both the conditions should be satisfied right? one side is 1 that is okay. but other side may come zero. so how it returns 1.
0
can you please explain how it works