How is the value of b
unchanged?
#include <iostream>
int main()
{
int a = 5, b = 10;
if (++a || ++b)
std::cout << a << b;
system("PAUSE");
return 0;
}
The output is 610
. But how?
How is the value of b
unchanged?
#include <iostream>
int main()
{
int a = 5, b = 10;
if (++a || ++b)
std::cout << a << b;
system("PAUSE");
return 0;
}
The output is 610
. But how?
here's how the 'if' statement works:
if(condition1 || condition2 || condition 3){
//do this
}
now if condition1 is true (which in your code, it is since a!=0), the execution straightaway moves inside the block without checking 2 and 3.
If you wish to increment b as well, try && in place of ||