Which order is the and && operator evaluated
For example the following code
if (float alpha = value1-value2 && alpha > 0.001)
//do something
threw an exception that alpha is being used without being initiated. I thought the expression left of the && would always initiate the value of alpha first, but it seems I may be wrong
Any idea?
Thanks
Left side is driver side, right side is passenger side. It is important to understand Right Hand vs.
Page numberingPage 1 and all odd-numbered pages are always right-hand pages. Page 2 and all even-numbered pages are always left-hand pages.
This gets parsed as:
if (int alpha = (value1-value2 && (alpha > 0.001)))
... because &&
has a higher "parsing precedence" than =
-- which is probably not what you want. Try:
int alpha = value1-value2;
if (alpha && (alpha > 0.001))
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