The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

reply Inc Test

Posted by Pritpal Singh on December 20, 2000 at 2:13 AM

Your problem is u r using post increment operator
actually it assigns value first to variable "i" and then increment it
the result is 10

i.e. i = i++ means
i = 10
and in memory increase it by 1 after that initialization

if u use ++i you will get 11 as answer



> Hi
> can any one please explainf me why the below program is printing 10 insted of 11
> public class incTest
> {
> public static void main(String [] arg)
> {
> int i = 10;
> i = i++;
> System.out.println(i);
> }

> }
> Thanx & Regard
> Ramesh






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us