| | |
Priority in Operators
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
•
•
Join Date: Dec 2008
Posts: 7
Reputation:
Solved Threads: 1
Primary (x) x.y f(x) a[x] x++ x--new typeof sizeof checked unchecked
Unary + -~ ! ++x --x (T)x
Multiplicative * / %
Additive + -
Shift << >>
Relational < > <= >= is as
Equality == !=
Logical AND&
Logical XOR^
Logical OR|
Conditional AND&&
Conditional OR||
Conditional c?x:y
Assignment = += -= *= /= %= <<= >>= &= ^= |=
Operators on the same level are evaluated from left to right
For better programming skills remember above priority in operators.
Thanks,
Anuj
Unary + -~ ! ++x --x (T)x
Multiplicative * / %
Additive + -
Shift << >>
Relational < > <= >= is as
Equality == !=
Logical AND&
Logical XOR^
Logical OR|
Conditional AND&&
Conditional OR||
Conditional c?x:y
Assignment = += -= *= /= %= <<= >>= &= ^= |=
Operators on the same level are evaluated from left to right
For better programming skills remember above priority in operators.
Thanks,
Anuj
•
•
Join Date: Dec 2008
Posts: 53
Reputation:
Solved Threads: 6
For more effective programming, don't try and memorise this list; bracket expressions appropriately so that any programmer can read them whether or not they have also memorised this list (practically nobody has). OK, it's probably safe to assume that most programmers know that * and / have priority over + and -. But beyond that, nobody generally remembers or cares that, say, AND has higher precedence over XOR. And nobody is going to think you're a "better programmer" because you've pointlessly memorised this list.
N.B. This list isn't "handed down by God". It's valid for C, Java and other languages that have deliberately chosen to use the same order of precedence. But some other language could choose to use a different order.
N.B. This list isn't "handed down by God". It's valid for C, Java and other languages that have deliberately chosen to use the same order of precedence. But some other language could choose to use a different order.
Last edited by neilcoffey; Dec 29th, 2008 at 10:56 pm.
> For better programming skills remember above priority in operators
I've been doing C for 20 years, and I still can't be bothered to remember it.
The same goes for a large part of the standard C library. I know what functions exist, but I don't remember parameter orders for every single one of them (that's what man pages are for).
I know roughly where everything goes, but if the expression becomes too complex (which is a hint in itself), then I just use ( )
Besides, if you're writing code commercially, you have to figure that at some point, someone who knows less C than you will be maintaining it at some point. So it pays to be not overly clever with your code.
I've been doing C for 20 years, and I still can't be bothered to remember it.
The same goes for a large part of the standard C library. I know what functions exist, but I don't remember parameter orders for every single one of them (that's what man pages are for).
I know roughly where everything goes, but if the expression becomes too complex (which is a hint in itself), then I just use ( )
Besides, if you're writing code commercially, you have to figure that at some point, someone who knows less C than you will be maintaining it at some point. So it pays to be not overly clever with your code.
![]() |
Similar Threads
- Help With Simple Equation Parsing (C++)
- Identify || statements (C++)
- how to compute a string in c#??? (C#)
- order of evaluation (C)
- Help for Binary Tree Traversal for infix to postfix conversion (C++)
- mysql_num_rows warning (PHP)
- iterating arrays. (VB.NET)
- wrong output (C++)
- Any Boolean Expression to Sum of Minterms (C++)
Other Threads in the Computer Science Forum
- Previous Thread: How to design and plan a program
- Next Thread: An introduction to Test Driven Development
| Thread Tools | Search this Thread |
ai algorithm algorithms amazon assignmenthelp assignments automata battery bigbrother binary bittorrent bizarre bletchleypark blogging bomb business cern codebreaker compiler computer computers computerscience computertrackingsoftware connect conversion csc data dataanalysis dataintepretation development dfa dissertation dissertations dissertationthesis employment energy extensions foreclosure foreclosuresoftware fuel gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea internet iphone ipod itcontracts kindle laser laws linkbait lsmeans mainframes marketing mining mobileapplication msaccess nano netbeans networking news os p2p piracy piratebay principles programming rasterizer research sam-being-cute sas science sex simulation software spying sql stephenfry study supercomputer supercomputing sweden technology textfield turing turingtest two'scompliment uk warehouse ww2






