Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #9005
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Wed, 19 Oct 2011 12:47:53 -0500 |
| Date | Wed, 19 Oct 2011 18:47:58 +0100 |
| From | Patricia Shanahan <pats@acm.org> |
| User-Agent | Thunderbird 1.5.0.2 (Windows/20060308) |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: A freshman's question |
| References | <3242b80f-ee51-45f0-9e12-231482f61a97@r2g2000prh.googlegroups.com> <37KdnWZAYfIR1QPTnZ2dnUVZ_vWdnZ2d@earthlink.com> <02a66b06-651a-46c8-9a09-64442a73a959@s17g2000prm.googlegroups.com> <F4mdnVWUC_HXFQPTnZ2dnUVZ_oednZ2d@earthlink.com> <4df1e05a-295c-4c60-9baf-0e69cd4ee507@r2g2000prh.googlegroups.com> <17976081.108.1319043493265.JavaMail.geo-discussion-forums@yqjh13> |
| In-Reply-To | <17976081.108.1319043493265.JavaMail.geo-discussion-forums@yqjh13> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Message-ID | <ScSdnekftejUkALTnZ2dnUVZ_gydnZ2d@earthlink.com> (permalink) |
| Lines | 84 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 83.244.254.136 |
| X-Trace | sv3-RVN9O0yF/HFnG3QUG2i0MWZzHc2R5tT2mqLxl1Zq3q2RBGigzXIxfyIUXGIf+UkDWOVCT5aR1jkzSKC!J63Lb9rhFiT1PRB7ROJHz/o018yek+YdmWsn9DON3f2XksafSui/F3GCI/A/gaY10ex3gwzsm2N9!gr6j08fx9YqawhRDCGMBKdJJadNroxAVNssf95TGulBhDPA= |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 4648 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9005 |
Show key headers only | View raw
Lew wrote:
> whl wrote:
>> Patricia Shanahan wrote:
>>> whl wrote:
>>>> Patricia Shanahan wrote:
>>>>> whl wrote:
>>>>>> ======start=========
>>>>>> public class Inc{
>>>>>> public static void main(String argv[]){
>>>>>> Inc inc = new Inc();
>>>>>> int i =0;
>>>>>> inc.fermin(i);
>>>>>> i = i++;
>>>>>> System.out.println(i);
>>>>>> }
>>>>>> void fermin(int i){
>>>>>> i++;
>>>>>> }
>>>>>> }
>>>>>> ========end========
>>>>>> I think the result is 1,but the real result is 0. I don't kown the
>>>>>> statement i=i++ operation sequence. In my opinion , variable i's
>>>>>> values is 0,then i++ ,the variable i's values is 1. They share a
>>>>>> common memory space,the variable i should change the values.
>
>>>>> The i=i++ operation sequence is:
>>>>>
>>>>> 1. Evaluate i++. It has the side effect of incrementing i to 1, but has
>>>>> as result the old value of i, 0.
>>>>>
>>>>> 2. Do the assignment. This sets the left hand side, i, equal to the
>>>>> result of the right hand side, 0.
>>>>>
>>>>> In theory, i does change to 1, but immediately changes back to 0. In
>>>>> practice, the change in i's value might get optimized out. The effect of
>>>>> i=i++ is to leave i unchanged.
>>>> so ,thank you for you answer my question ,I just don't know the
>>>> variable i is share the common memory space and when the left hand
>>>> side ,i ,equal to the result of the right hand side ,0,then ,i
>>>> increase to 1,so ,in the memory ,the variable i's value should be 1.if
>>>> change the expression i=i++ to i++,the result is 1.
>>> Look again at what I wrote.
>>>
>>> During step 1, at least in theory, i changes from 0 to 1. If the entire
>>> statement is "i++;" that is the value of i for later statements. The 0
>>> result of evaluating i++ is not used.
>>>
>>> In the original case, step 2 makes i equal to the value of the right
>>> hand side, 0, and that is the value of i for later statements.
>> Thank you for your explanation in patience, maybe my English is very
>> terrible,I don't understand all of your meaning. your meaning is when
>> the variable i on the right hand side is assigned 0,then ,the
>> statement "i++" don't execute,and start print?
>
> No.
>
> The "i++" *does* execute. ("print" has nothing to do with this yet.)
>
> What is the value of 'i++'?
>
> Let's just look at two lines of code.
>
> int i = 0;
> int x = i++;
>
> What is the value of 'x' after its initialization?
>
> Zero!
>
> Why?
>
> Because the value of a post-increment expression - that means the '++' is to the right of the variable - is the value of the variable before the increment.
>
> This is very, very basic.
I'm beginning to think the problem may be even more basic.
Does whl realize that the right hand side of an assignment is completely
evaluated, including all side effects, before the assignment?
That means that the incrementing of i due to the i++ is done and over
before the value of the i++ expression is assigned to i.
Patricia
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-18 20:08 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-19 04:48 +0100
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-19 00:54 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-19 09:20 +0100
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-19 03:38 -0700
Re: A freshman's question Lars Enderin <lars.enderin@telia.com> - 2011-10-19 17:48 +0200
Re: A freshman's question Tim Slattery <Slattery_T@bls.gov> - 2011-10-19 12:24 -0400
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 03:55 -0700
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 03:50 -0700
Re: A freshman's question Lew <lewbloch@gmail.com> - 2011-10-19 09:58 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-19 18:47 +0100
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 03:48 -0700
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-19 03:49 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-19 18:58 +0100
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 02:13 -0700
Re: A freshman's question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-10-19 06:05 -0300
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-19 03:38 -0700
Re: A freshman's question Travers Naran <tnaran@gmail.com> - 2011-10-20 07:30 -0700
Re: A freshman's question Gene Wirchenko <genew@ocis.net> - 2011-10-20 10:08 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-20 18:22 +0100
Re: A freshman's question Lew <lewbloch@gmail.com> - 2011-10-20 13:59 -0700
Re: A freshman's question Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-10-20 17:38 -0500
Re: A freshman's question Roedy Green <see_website@mindprod.com.invalid> - 2011-10-19 23:56 -0700
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 03:55 -0700
csiph-web