• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

post increment

 
Arun Prasath
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact this is asked so often that we have a FAQ entry for it: http://faq.javaranch.com/view?PostIncrementOperatorAndAssignment
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted by Joanne Neal
I would expect it to print 0.
I tried it. I got "0."
 
Chetan Raju
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic