Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how do i remember the operator precedence  RSS feed

 
Gadi Reddy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can any one help me regarding operator precedence and associtivity.

how can i remember the sequesnce(please tell me some short cut or idea)
Regards,
Raghu
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The math ones are all normal, and the rest tend to make sense, like casts casting the closest thing. Since we like making our code easy to read, it's probably a good idea to just use parentheses anytime you would otherwise be forced to remember the order.
[ January 18, 2006: Message edited by: Nick George ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Nick: don't remember it, use parantheses so that you don't have to (for other than the obvious cases, that is).
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not print out the table in this reference and stick it by your monitor? I stick all sorts of stuff I really should know but can't keep in my head on my cubicle partition wall by my PC. My wall of shame:

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Nick and Ilja: don't waste precious storage space trying to memorize operator precedence. For mathematical operators, the precedence is the same as the "order of operations" that you learn in pre-algebra. For everything else, use parentheses to make the order of evaluation entirely clear.

Layne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!