Hey guys, just wondering if use know any tips in remembering the operator precedence. As I have to start knowing these off by heart and I'm always putting a couple in the wrong place hah. So yeah any tips on how to remember them all in order would be great :)
some of them have the same precedence relations as in maths:
+ / higher precedence than + -
= += etc. have a really low precedence as they have to assign value from expressions
?: have a higher precedence than those as you should be able to write this : a = b ? c : d;
unary operators usually have a really high precedence eg: *ptr + 1
So remember how you would use them and you will remember them.
However if you are not sure you can use parentheses
Thanks Bazzy what you've said I understand and know but - My problem is all of this has to be written in order on a written test. So I'm trying to pull my head around remembering them all in order correctly and not forgetting one.
Doing my best though to make sure I don't miss one :)
Here's a mnemonic I just made up:
So usually unless Steve, my dad, makes a saxophone, Steve can't exactly assemble xylophones or an oboe till a trashman comes.
Scope (::)
Unary special (function calls, casts, member access (like ->), POST ++/--, etc)
Unary normal (!, ~, - (as in -1), */&. new/delete, etc)
Selectors (->* and .*, I wouldn't worry about this one so much)
Multiplication/Divisision/Modulo
Addition/Subtraction
Shifts (<<, >>)
Comparators (non-equality, <, >, <=, >=)
Equality comparators (==, !=)
And - bitwise (&)
Xor - bitwise (^)
Or - bitwise (|)
And - logical (&&)
Or - logical (||)
Ternary ( cond ? resultIfTrue : resultIfFalse )
Assignment (=, +=, >>=, etc)
Throw (throw)
Comma (,)
Just remember that that math ones */% and +- go just like in normal math and not on separate levels like I've implied here, I just wanted to make it clear the general order.