+5

# What is the correct sequence for multioperation arithmetic or precedence?

Some have written * / % + - = while others % / * - + =

2/12/2019 8:51:29 PM

Navigator Moses

+8

nice table HonFu yeah seems modulo and * and / all have same level of precedence, and precedence between them is determined from left to right. therefore always good to put parenthesis just in case

+7

Sonic unfortunately they do! '(!0+1)' in C evaluates as true, while 'not 0+1' in Python would be false. ! is very quick in C, so it's like 1+1, while in Python it would be 'not (0+1)'. '(4>5==4>5)' is true in C, because the comparisons are quicker, so 0==0 -> True. In Python they have the same precedence, so they get chained, so after 4>5 it's already false. That's one of the mean pitfalls of trying to learn several languages: Things may look similar, but sometimes act differently behind the scenes.

+7

Thanks HonFu . That blows my chance of becoming proficient in several languages, well partially anyway.

+6

i always wondered about this detail. i would assume * and / have precdence over + and - . not sure about the modulo though. will have to do a code to test it.

+6

It would be nice if all languages used the same precedence. I am not sure if some languages follow a slightly altered precedence.

+5

https://code.sololearn.com/cWm8qG9DuZIz/?ref=app in conclusion it can be %/* or /*%. depends on what is first from left to right.

+3

I think you should find everything here: https://en.cppreference.com/w/c/language/operator_precedence

+3

Sonic, we just have to make our peace with the fact that none of these languages is as simple as the tutorials seem to suggest, and we need to learn more, watch out and ask many, many 'what ifs'.

+1

Both are correct because *, % , / have same precedence but the operation will evaluate from left to right means the first encountered operator evaluate first then corresponding And also +, - have same precedence and follow same logic.