Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Arithmetic precedence ??

Greenhorn
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

Henry Wong
author
Marshal
Posts: 21741
85
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

Greenhorn
Posts: 8

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,

Henry Wong
author
Marshal
Posts: 21741
85
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

Greenhorn
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,

Henry Wong
author
Marshal
Posts: 21741
85
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
Posts: 50702
83
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
Posts: 50702
83
And welcome to JavaRanch