How to work operators? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

How to work operators?

How to work operators, Left to right or right to left?

17th Jan 2022, 2:23 AM
Anjali Kumari
8 Answers
+ 5
operator precedence defines the order in which operators are evaluated, If there are multiple operators of same precedence, the evaluation is done on the basis of their associativity. This is generally same as what you would find in traditional maths ( following the BODMAS rule for precedence ) but languages are free to alter them according to their needs ( although there are only a few exceptions where they actually do that ), so it's preferred to actually look up a reliable docs of the language you are using to know the right precedence and associativity. for example (C++) : https://en.cppreference.com/book/operator_precedence
17th Jan 2022, 2:39 AM
Arsenic
Arsenic - avatar
+ 4
Here is what BODMAS stands for: B--> Brackets O--> Order of powers or roots D--> Division M--> Multiplication A--> Addition S--> Substraction
18th Jan 2022, 5:32 PM
Yusuf
Yusuf - avatar
+ 3
Left to right if they have same operator precedence.
17th Jan 2022, 2:27 AM
Simba
Simba - avatar
+ 3
If they not same precedence?
17th Jan 2022, 2:28 AM
Anjali Kumari
+ 3
Though boadmas and ofcourse use parenthesis () to solve each of them to resolve with ease..
18th Jan 2022, 5:06 PM
Devansh Tiwari
Devansh Tiwari - avatar
+ 2
BODMAS
17th Jan 2022, 2:28 AM
Simba
Simba - avatar
+ 2
B--> Brackets O--> Order of powers11 DM--> Divisions and Multiplications left to right AS--> Additions and Substractions left to right
18th Jan 2022, 11:56 PM
Nathaniel
Nathaniel - avatar
+ 1
BODMAS Bracket Power Divide Multiply Add Sub
18th Jan 2022, 5:36 PM
Hellock