Can anybody explain (step by step) to me why the following program output 8? I was expecting 3 as the output.
int main()
{
int a=5,b=2,c=9,d=1;
b*=!d+b-(a==5||--b)+(c=3);
cout<<b<<endl;
return 0;
}
PS: I'm not that naive in programming. 8 is the possible output only if b retains it's value as 2 but I think it has already decremented to 1 in (a==5||--b).
Yes, but the C++ language doesn't guarantee what the result will be. It probably just happened to be 8 because the compiler does it in a certain way, but this is nothing you should rely on. Things like this might change when you modify your code or use different compiler settings.