+ 5

What is the correct sequence for multioperation arithmetic or precedence?

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

12th Feb 2019, 8:51 PM
Navigator Moses
Navigator Moses - avatar
9 ответов
+ 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.
13th Feb 2019, 8:36 AM
HonFu
HonFu - avatar
+ 7
Thanks HonFu . That blows my chance of becoming proficient in several languages, well partially anyway.
13th Feb 2019, 8:40 AM
Sonic
Sonic - avatar
+ 6
It would be nice if all languages used the same precedence. I am not sure if some languages follow a slightly altered precedence.
13th Feb 2019, 4:02 AM
Sonic
Sonic - avatar
+ 3
I think you should find everything here: https://en.cppreference.com/w/c/language/operator_precedence
12th Feb 2019, 10:09 PM
HonFu
HonFu - avatar
+ 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'.
13th Feb 2019, 9:31 AM
HonFu
HonFu - avatar
+ 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.
26th Feb 2019, 3:15 PM
Surya Prakash Giri
Surya Prakash Giri - avatar