• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

which is given priority in increment?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know which incrementaion will be first in this case
here d is 7
d= d - (d+=5) + d++;
whether d+=5 or d++ and why?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niti,
d+=5 will be evaluated first because you have put it inside of (), which has a higher precedence thatn +, -, and ++.
Nick
 
Niti Gupta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nick,
but if the case is d++ - ++d + --d + d++ + d-- then which will be the first to increment.
one more thing though in any case "++" is given first priority,but out of this a)++d OR b)d++ will be given priority.
Thanks once again.
Waiting for reply...
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Niti,
When operators have the same priority they are evaluated left-to-right.
Evaluation of your example, assuming d=0, would be:
<pre>
x = d++ - ++d + --d + d++ + d--
0 2 1 1 2
-2 1 1 2
-1 1 2
0 2
2 Final result assigned to x
</pre>
Value of d: 1 (last operator is a postfix)
You can use a neat trick to 'dump' intermediate results. Ajith Kalembella used it in one of his posts

Hope that helps.
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiousity.
-- Dorothy Parker
[This message has been edited by Jane Griscti (edited November 02, 2000).]
[This message has been edited by Jane Griscti (edited November 02, 2000).]
 
Niti Gupta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Janes,
Thanks for the answer,it really helped me.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!