Priority in Operators

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: Dec 2008
Posts: 7
Reputation: anujtripathi is an unknown quantity at this point 
Solved Threads: 1
anujtripathi anujtripathi is offline Offline
Newbie Poster

Priority in Operators

 
0
  #1
Dec 21st, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 53
Reputation: neilcoffey will become famous soon enough neilcoffey will become famous soon enough 
Solved Threads: 6
neilcoffey neilcoffey is offline Offline
Junior Poster in Training

Re: Priority in Operators

 
1
  #2
Dec 29th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Priority in Operators

 
1
  #3
Dec 30th, 2008
> 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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,479
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 514
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Priority in Operators

 
0
  #4
Dec 30th, 2008
++ 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).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC