This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Arithmetic precedence  ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arithmetic precedence  ??" Watch "Arithmetic precedence  ??" New topic
Author

Arithmetic precedence ??

nada saif
Greenhorn

Joined: Nov 14, 2009
Posts: 8
Hi ,

I want to know about Arithmetic precedence , i read the table but how it says ++ ,-- has higher priority than =

and this example says opposite i=a++;


can any boy elaborate here?


Thanks

Nada
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18497
    
  40

nada saif wrote:
and this example says opposite i=a++;


A post increment means increment, but its original value is used for the expression. So, it is done first -- it is just that the "a++" value is the original value of a.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
nada saif
Greenhorn

Joined: Nov 14, 2009
Posts: 8
Thanks for replying Henry ,

Still i am n't getting it completely

How i can use this table http://www.uni-bonn.de/~manfear/javaoperators.php

to deal with the same example i=a++


Thanks,


Nada

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18497
    
  40

nada saif wrote:to deal with the same example i=a++


The precedence is *not* enough. You also need to understand what each operation does (along with association and order of evaluation for more complex expressions) too.

As for your example, I don't know how you came to the conclusion of that precedence -- so I can't elaborate... except to say if ...

i=a++;

has a precedence of...

(i=a)++;

doesn't that come out to a syntax error?

Henry
nada saif
Greenhorn

Joined: Nov 14, 2009
Posts: 8
Thank you , and sorry for asking Question like that i know it's not reasonable ..
But i wanted to be sure about stuff like that and specially when students come to ask ..



Best wishes,

Nada
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18497
    
  40

nada saif wrote:Thank you , and sorry for asking Question like that i know it's not reasonable ..
But i wanted to be sure about stuff like that and specially when students come to ask ..


There is nothing "not reasonable" about your question. You made an observation which seem to cause a contradiction, and wanted to resolve it.

And definitely nothing to be sorry about...

Henry
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Henry is correct; there is nothing wrong with your question. Search for "postincrement Preincrement" or "post increment pre increment" here and you will see many people have similar problems.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
And welcome to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arithmetic precedence ??
 
Similar Threads
String Literal
question( i++/++i )
Is assignment precedence(=) higher than postfix unary assignment(var++)
working of increment operator
Operator Precedence in Java