This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes post increment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "post increment" Watch "post increment" New topic
Author

post increment

Arun Prasath
Ranch Hand

Joined: Jul 18, 2006
Posts: 60
20: int i=0;
21: int j=i++;
22; System.out.println(j); // prints 1;

I feel ok with this code...
---------------------
In the following snippets,..

10: int i=0;
11: i=i++;
12; System.out.println(i); // prints 0;

what is happening to the post increment operation..?tell me in detail..
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Originally posted by Arun Prasath AV:
20: int i=0;
21: int j=i++;
22; System.out.println(j); // prints 1;

I feel ok with this code...
---------------------
In the following snippets,..

10: int i=0;
11: i=i++;
12; System.out.println(i); // prints 0;

what is happening to the post increment operation..?tell me in detail..


Although this doesn't seems to be an Advanced topic.. You should take care while posting your questions in the right forum. Asking a begineer's question in advance forum doesn't help you to get early reply.
So next time please take care..

Although the same discussion has been done earlier..

check out the following thread...

How Post Increment Operators works

It will be benifitial for you, and can answer your all questions.

[ August 03, 2006: Message edited by: Ankur Sharma ]

The Best way to predict your future is to create it - Every great individual common man
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
15.14.2 Postfix Increment Operator ++

The value of the postfix increment expression is the value of the variable before the new value is stored.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
In fact this is asked so often that we have a FAQ entry for it: http://faq.javaranch.com/view?PostIncrementOperatorAndAssignment


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3431
    
  12
Originally posted by Arun Prasath AV:
20: int i=0;
21: int j=i++;
22; System.out.println(j); // prints 1;

I feel ok with this code...


Are you sure about that ? I would expect it to print 0.


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38043
    
  22
Posted by Joanne Neal
I would expect it to print 0.
I tried it. I got "0."
Chetan Raju
Ranch Hand

Joined: Aug 02, 2006
Posts: 109
Originally posted by Arun Prasath AV:
20: int i=0;
21: int j=i++;
22; System.out.println(j); // prints 1;

I feel ok with this code...


It will not print 1.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: post increment
 
Similar Threads
Doubt on Post Increment operator.
assignment operator with post increment
post increment
post(not)incremented?
Evaluation problem