0
int a=-1; cout<<(a++&&1); why output is 1?not 0?
tanks
4 Respostas
0
why did you add &&1 for ?
and a++ mean you would print a then add by 1. Thats why it's not 0,
meaning if u print a again it will be 1.
Use ++a instead which will add by 1 then print a.
0
You are using a logical operator, which will return a boolean value (true or false).
In C++, 0 is equal to false and every other number equal to true.
The "and" operator returns true of both values are true, otherwise false.
So -1 is true AND 1 is true, so the expression is true.
As a result, the value 1 is printed to the screen.
Hope this helps.
0
@Naitoma,jayrn02 what is the function(why we need it) of && at this moment?from sololearn l know ,only that &&is using when we are working with conditions-if(5>3&&4<6){cout<< ....
0
yes && is for conditions which means and. You usually use it if you want 2 conditions to be true and if 1 is false and the other is true, its consider false regardless which is true