This week's book giveaway is in the Programmer Certification forum. We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Hello Here is a sample of code int i = 0; i=i++; System.out.println(i); Can you guess what will be the output ? Output is 0. Could anybody explain the reason !!
Hi Manali, I have a piece of code similar to the one u have written.. the output is 1 for the following code... wonder why ?? int a,i = 0; a = i++; System.out.println(i); Can anyone explain this ? Praveen Zala
Originally posted by manali: Hello Here is a sample of code int i = 0; i=i++; System.out.println(i); Can you guess what will be the output ? Output is 0. Could anybody explain the reason !!
Hi, this topic has been discussed around July 15, I just cna not find the link, if u have time, check it. mick
Hi Manali Here is what I think the answer is: The operation i = i++ can be thought of as 2 atomic operations i = i and i = i + 1 When the first operation takes place the value of i = 0 is placed on the stack, when the second operation happens the value of i = 1 is placed on the stack. However in a stack is a LIFO list. So what comes out first is i = 1 and then i = 0. Thus i = 0 overwrites the previous value of i = 1 Hope this explaination helps.
Sun Certified Java Programmer<BR>Oracle Certified DBA
Evil is afoot. But this tiny ad is just an ad:
Gift giving made easy with the permaculture playing cards