+ 4

Doubt

If `%` operator has highest precedence then why 5*4%3 results 2 in many languages instead of 5.

4th Jun 2024, 6:56 AM
You
2 Answers
+ 9
Since multiplication and division have the same precedence, they are evaluated from left to right.
4th Jun 2024, 7:34 AM
Keith
Keith - avatar
+ 2
Because in many languages '%' it have the same precedence as '*' and thus, 5*4%3 starts with '*' first instead of '%'
5th Jun 2024, 2:42 PM
Nisha Choudhari
Nisha Choudhari - avatar