943,910 Members | Top Members by Rank

Ad:
Dec 21st, 2008
0

Priority in Operators

Expand Post »
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
Similar Threads
Reputation Points: 7
Solved Threads: 1
Newbie Poster
anujtripathi is offline Offline
7 posts
since Dec 2008
Dec 29th, 2008
1

Re: Priority in Operators

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.
Last edited by neilcoffey; Dec 29th, 2008 at 10:56 pm.
Reputation Points: 120
Solved Threads: 7
Junior Poster in Training
neilcoffey is offline Offline
53 posts
since Dec 2008
Dec 30th, 2008
1

Re: Priority in Operators

> 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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Dec 30th, 2008
0

Re: Priority in Operators

++ to both of the above posts.
If you're writing a lot of code that depends on knowing that list well, no one will want to work with you (including yourself when you are trying to track down your own bugs 3 months later).
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: How to design and plan a program
Next Thread in Computer Science Forum Timeline: An introduction to Test Driven Development





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC