+ 2

What is Operator precedence

I don’t understand it

21st Feb 2018, 7:59 PM
TimbersledAnarchy
TimbersledAnarchy - avatar
9 Answers
+ 6
In math it's what you call the "Order of Operations." Same concept applies since programming is mostly math concepts. https://en.wikipedia.org/wiki/Order_of_operations "The order of operations used throughout mathematics, science, technology and many computer programming languages is expressed here: 1. exponents and roots 2. multiplication and division 3. addition and subtraction" When I was growing up in school, we had PEMDAS, "please excuse my dear aunt sally." Parenthesis Exponents Multiplication Division Addition Subtraction ^That's the order I was taught from what takes highest precedence to least.
21st Feb 2018, 8:13 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
what is the result of 3*1+1 ? how about 3*(1+1). ? result of first one is 4. since first the multiplication comes. then addition. 3*1 =3 , 3+1 =4 result of second is 6. since we declared that the addition must happen first (by putting them in () ). and then multiplication. 1+1=2,. 3*2=6
21st Feb 2018, 8:05 PM
Farshaad Heydari
Farshaad Heydari - avatar
+ 2
do you. have an example ? maybe in code...
21st Feb 2018, 8:11 PM
Farshaad Heydari
Farshaad Heydari - avatar
0
I understand that one but if you add boolean it gets complicated
21st Feb 2018, 8:09 PM
TimbersledAnarchy
TimbersledAnarchy - avatar
0
False == (False or True) does it mean false == true ?
21st Feb 2018, 8:12 PM
TimbersledAnarchy
TimbersledAnarchy - avatar
0
Thnx
21st Feb 2018, 8:18 PM
TimbersledAnarchy
TimbersledAnarchy - avatar
0
as mentioned by @maxwell. parentheses has highest priority. so first, the code inside them will be evaluated then the rest .....
21st Feb 2018, 8:19 PM
Farshaad Heydari
Farshaad Heydari - avatar
0
Ok I
21st Feb 2018, 8:22 PM
TimbersledAnarchy
TimbersledAnarchy - avatar