Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.glorb.com!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: Sun, 11 Sep 2011 21:25:10 -0500 Message-ID: <4E6D6D89.6AEF@mindspring.com> Date: Sun, 11 Sep 2011 22:25:13 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Unexpected output References: <8787e0b5-b4c3-463f-bd9a-6ffc30034950@x29g2000prh.googlegroups.com> <0.ebf783d11b675daee4a9.20110911225116BST.87obyq21ez.fsf@bsb.me.uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 37 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.216.193 X-Trace: sv3-gBOt9P6CJ8l+Ggx6LOoumgvjZ4cVrCL7XoeKboi2E+VVZ1xkJko6FDeyX5L3fJCL26rwntLSlMuF3eX!USBeC/u36TqLixbaXR+m5Fe6RspZpG0anW9LmgbzSvmTfbMkH2K4pcO+6HA64kkKLkEH16rR4zpx!4QwhLf4oYfU= 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: 1968 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:10149 Ben Bacarisse wrote: > > August Karlstrom writes: > > > On 2011-09-10 21:36, Mazen wrote: > >> Hello, > >> > >> Following is a simple program: > >> > >> #include > >> > >> int main(void) { > >> int i = 0, j, k; > >> j = k = 2; > >> > >> printf("%d %d\n", i=+j, i=-j); > >> > >> return 0; > >> } > >> > >> The output is > >> 2 2 > >> > >> Shouldn't the second expression be -2 rather than 2? I'm confused. > >> Your insights pls. Thanks! > > > > One obvious insight is that it's best to avoid side effects in > > expressions if possible. > > The devil is in the detail. You presumably think that x = 1; is OK so > what about x++? (x = 1) has a side effect in an expression. I avoid side effects in arguments in function calls. -- pete