• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when we use pre increment and when we use post increment

 
aditya chaudhari
Ranch Hand
Posts: 31
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly when we use pre and post increment..??
I know the working of pre and post increment perfectly
But i want to know what exactly is the difference between them in terms of using them.
i mean when we use pre increment and when we use post increment
i googled it out but didnt got satisfactory answer( may be it was not of my understanding level answers).
This is right place where i can get my answer surly .
Please tell me .
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aditya chaudhari wrote:Exactly when we use pre and post increment..??

Let say, you declare variable to int pos = 0; then you have to do

you declare variable to int pos = 1; then

 
aditya chaudhari
Ranch Hand
Posts: 31
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Seetharaman I got my answer now i will look for similar example like you
You clear my doubt
Thanks
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's my strategy for when to use those two similar-looking features:

I don't ever use them in a place where I do anything with the result of the incrementation (is that the word?). And that means that they are interchangeable. Both of them increment the variable they are applied to, but I don't have to know which of them does what after that.

I would recommend you do that too. Sure, for the certification exam you have to know which is which, but in the real world of programming it's much easier to do it my way.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic