+ 2
Here why 'y' value is 1?
#include <iostream> using namespace std; int main() { int x,y,z; x=y=1; z=++x||++y; cout<<x<<y<<z; return 0; } output :211 IF we use " logical and " operater instead of " logical or " y value is 2. also z=++x||(++y) gives y as 1
1 Answer
+ 2
I think its because when you have a logical or operator it checks if the first condition is true then stops checking the rest as it doesnt matter so ++x is true so no need to carry on.