bool bSwitch = true;
double dSum = 1 + bSwitch?1:2;
So "dSum" is:
a)=1
b)=2
c)=3
The result is just rediculous and i got bashed for it...
I'm using VS2008 -> "Microsoft (R) 32-Bit C/C++-Optimierungscompiler Version 15.00.21022.08 für 80x86"
operator+
has higher precedence, than the ternary operator ?:
.
So, this is equivalent to
double dSum = ( 1 + bSwitch ) ? 1 : 2;
Thus, you have dSum == 1
.
It's a precedence thing isn't it.
bool bSwitch = true;
double dSum = (1 + bSwitch)?1:2;
dSum
will be 1.0
Would have been easier to spot with sensible spacing around the operators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With