Originally posted by Dan Culache:
Ramnath, you raised my doubts now?!
Are you implying that + and - are not unary operators?
Dan ,
They come under both categories....
I am trying to explain the distinction/....lets see how I will fare
caution...these rules are framed by me for myself... i dont know whether they exist somewhere
the operator precedence goes like , unary and then arithmetic
unary consists of (as someone else already said)
++,--,+,-,!,~,()(cast operator)
in this + and - can be recognized because they are always the prefix of the operand
i,e +4, +5 , +6, -5, -7.5
Arithmetic operators are *,/,% , +,-
these operate between two operands
i,e 5 + 6 , 6 - 5 and so on
Now there can be some tricky situations like
6+ +5 ,
in these situations it is calculated as 6 + (+5)
because unary + has higher precedence over arithmetic operator + .
but if you see something like
6++5 , then it is a compiler error. I have read that
java takes the longer version of operators always (listen...I am not really sure about the statement.... i think I have read it in Dan's exams). I might be wrong....over to our great Dan Chisholm to continue
Thanks and hope it will clear atleast some of your doubts
Sri