• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

post increment

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76860
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Posted by Joanne Neal

I would expect it to print 0.

I tried it. I got "0."
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No holds barred. And no bars holed. Except this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic