avi neo wrote:As mentioned in the book, post-unary operators have higher precedence than pre-unary operators.
Shouldn't the sequence have been something as follows ?
x is decreased by post-decrement operator (x--) Then it is increased by pre-increment operator (++x) Finally it is decreased by pre-decrement operator (--x)
Stephan van Hulst wrote:Operators are not evaluated, because they are not expressions.
avi neo wrote:It would be great if somebody can clarify my doubt.
My one cow = 2 likes so gave him, at least for a month(Pie user)Roel De Nijs wrote:
Ganesh Patekar wrote:@Stephan Great explanation in detail.
It is indeed a great explanationHave a cow, Stephan!
+1 great post.It is indeed a great explanation. Have a cow, Stephan!
Stephan van Hulst wrote:
After that's done, the expression is evaluated left to right:
Daniel Cox wrote:My understanding is that all of the operands in the expression will first be evaluated from left to right before any operation takes place
After evaluation of all of the operands in the expression is complete, operators then operate on their operands based on precedence and associativity. So based on precedence and associativity, operators operate on their operands in this order
Daniel Cox wrote:My understanding is that all of the operands in the expression will first be evaluated from left to right before any operation takes place.
Stephan van Hulst wrote:Operators are not evaluated, because they are not expressions. Operations are evaluated.
Daniel Cox wrote:Just one more thing. Sometimes, information we get on the ranch conflicts with information we get from articles and books, so just to be clear, I want to confirm that these corrections are valid.
Trail: Learning the Java Language - Language Basics - Operators wrote:As we explore the operators of the Java programming language, it may be helpful for you to know ahead of time which operators have the highest precedence. The operators in the following table are listed according to precedence order. The closer to the top of the table an operator appears, the higher its precedence. Operators with higher precedence are evaluated before operators with relatively lower precedence. Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.
Stephan van Hulst wrote:
It's not technically correct, but it's generally accepted because the intention is clear.
Roel De Nijs wrote:And here is a little pop quiz question. What's the output of this code snippet?
Roel wrote:
Liutauras Vilda wrote:What would be printed?
Liutauras Vilda wrote:It seems you mastered this topic.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |