+ 5
What is the correct sequence for multioperation arithmetic or precedence?
Some have written * / % + - = while others % / * - + =
6 Answers
+ 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
It would be nice if all languages used the same precedence. I am not sure if some languages follow a slightly altered precedence.
+ 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.