This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Pl clear the very basic funda!

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int i = 0;
i = i++;
System.out.println(i);
The above code in a main statement of a class give output as 0 not 1 why?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int i = 0;
i = i++;
System.out.println(i);
The above code in a main statement of a class give output as 0 not 1 why?

in i = i++, the assignment operator is done first (l to r), so i is asssigned to i and the '++' is effectively ignored, as it is a post operation increment. Compare this to just i++ on line (2), which gives your expected 1 result
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a simple breakdown will surely help u:
y=x++
-------
can be broken down to :
y=x
x=x+1
==============
y=++x
-----
can be broken down to :
x=x+1
y=x(nothing but x+1)
this is the best explanation I found after many years of confusion
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good mnemonic for this:
j=i /* . . . . . . . */ ++ ;
(compiles and run)
Try this 4 sec training. For a permanent result.
Rythm it up (high or internal voice) 2 times as this:
i=i // say fast
... // wait..
++ // spit it now!
Now whenever you meet j=i++ in Mocks, the Test Center, or the real world, speak it:
j=i
...
++
JRoch

[This message has been edited by JRoch (edited April 07, 2000).]
[This message has been edited by JRoch (edited April 07, 2000).]
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sairam,
I have given an easy way out here. Check it out.
regds
maha anna
[This message has been edited by maha anna (edited April 07, 2000).]
 
Everybody! Do the Funky Monkey! Like this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic