We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
what is th eorder of presedents?
is 2 + 3 * 5 = 32 or 17
Where's the difficult question?
The difficult question is how to get 32.
It's easy in base 13.5!
Jon
are you joking? The precedence is the same that you use in mathematical equations.
2 + 3 * 5 is the same that 2 + (3 * 5) = 17. If you want 32 you have to do: (2 + 3) * 5 = 32
lol..
(3+2) * 5 = 32... ( !!! ??? !!! ) very Lol.... Next time I will check the calc.. :)
Never-Ever leave it to the compiler to define precidence, regardless of IDE compliance to ANSI/other standards.
Always use Parenthisis to be (CLEAR) about what you be are doin' at.
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
That sounds a bit too hard. The compiler do know the precendence rules, and the developer should know them too or have the access to the source code revoked.
Parentheses may be good for making the code faster to read in some situations, but I would not add parentheses for a three-argument equation with one add and one multiplication. No developer should need the parentheses for the readability.
But while parentheses may help with readability, too much parentheses makes the expression harder to read, forcing me to put the cursor on a parentesis just to see where the matching parenthesis is.
... Cpt Vince to spell "precedence" or "parenteses"!
;-)
Per, you are now in Violation of Section 4.5.2A. Expect the Code-Monkey Police to have you and your code impounded. </sarcasm>
"Never-Ever think that too many parentheses can be 'too many' within source code."
Andy, good one.
I once worked with a certain other well-known high-dollar commercial compiler where using too many parentheses actually caused it to generate incorrect code!
I think a far better rule is:
if you feel the need to add parentheses, then the expression is too complicated - break it down into separate steps
It is highly unlikely that this will have any negative impact on the code generated by a good, modern optimising compiler...
Andy,
I agree. Break it down into smaller statements!
* 918518FD-2C28-4BC6-AF11-83689E384065 thinks that 2 + 3 * 5 is broken down into a nice easyexpression not needing further subdivision, even if we still haven't figured out the OP:s suggested order of evaluation ;)
What is a presedent?
Is Obama the last in the list?
Indeed.
But, if it were more complex, and you were contemplating adding parentheses, then I'd recommend that you break it down instead.
I'm still trying to figure out how to get 32 out of that.