Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!74.125.46.80.MISMATCH!postnews.google.com!r2g2000prh.googlegroups.com!not-for-mail From: whl Newsgroups: comp.lang.java.programmer Subject: Re: A freshman's question Date: Wed, 19 Oct 2011 03:38:38 -0700 (PDT) Organization: http://groups.google.com Lines: 65 Message-ID: <4df1e05a-295c-4c60-9baf-0e69cd4ee507@r2g2000prh.googlegroups.com> References: <3242b80f-ee51-45f0-9e12-231482f61a97@r2g2000prh.googlegroups.com> <37KdnWZAYfIR1QPTnZ2dnUVZ_vWdnZ2d@earthlink.com> <02a66b06-651a-46c8-9a09-64442a73a959@s17g2000prm.googlegroups.com> NNTP-Posting-Host: 210.30.49.103 Mime-Version: 1.0 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1319021091 23134 127.0.0.1 (19 Oct 2011 10:44:51 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 19 Oct 2011 10:44:51 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r2g2000prh.googlegroups.com; posting-host=210.30.49.103; posting-account=HTLLjQoAAACz0TvVcFSbbOMA5uM_lEjQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HNKRUAELSC X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.218 Safari/535.1,gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8985 On Oct 19, 4:20 pm, Patricia Shanahan wrote: > whl wrote: > > On 10=D4=C219=C8=D5, =C9=CF=CE=E711=CA=B148=B7=D6, Patricia Shanahan wrote: > >> whl wrote: > >>> Dear all > >>> I am a freshman ,I from china, I have been learn java for > >>> mouths,my English isn't very well ,may my question expression is not > >>> very clear,but I hope I can learn with you together! thank you ! > >>> . when I do some test ,I found the question ,It is the code > >>> =3D=3D=3D=3D=3D=3Dstart=3D=3D=3D=3D=3D=3D=3D=3D=3D > >>> public class Inc{ > >>> public static void main(String argv[]){ > >>> Inc inc =3D new Inc(); > >>> int i =3D0; > >>> inc.fermin(i); > >>> i =3D i++; > >>> System.out.println(i); > >>> } > >>> void fermin(int i){ > >>> i++; > >>> } > >>> } > >>> =3D=3D=3D=3D=3D=3D=3D=3Dend=3D=3D=3D=3D=3D=3D=3D=3D > >>> I think the result is 1,but the real result is 0. I don't kown the > >>> statement i=3Di++ 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=3Di++ operation sequence is: > > >> 1. Evaluate i++. It has the side effect of incrementing i to 1, but ha= s > >> 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=3Di++ is to leave i unchanged. > > >> Patricia > > > 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=3Di++ 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. > > Patricia 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?