• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arithmetic precedence ??

 
nada saif
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21185
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
nada saif
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21185
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21185
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic