Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!uflorida!stat!sun13!vs2.scri.fsu.edu!murray From: murray@vs2.scri.fsu.edu (John Murray) Newsgroups: comp.sys.sgi Subject: Re: Fun and games with ++ operators Message-ID: <781@sun13.scri.fsu.edu> Date: 25 Sep 90 14:45:29 GMT References: <9009211942.AA07458@banach.aca.mcc.com> Sender: news@sun13.scri.fsu.edu Organization: SCRI, Florida State University Lines: 52 In article <9009211942.AA07458@banach.aca.mcc.com> nong@mcc.com writes: > >> #include >> int a [2]; >> main() >> { >> int i; >> a[0] = 5; >> a[1] = 6; >> i = 0; >> printf("%d %d\n", a[i++], a[i++]); >> } > >According to K&R ( p 59 1st edition, or 63 2nd edition ) >" The commas that separate function arguments, variables in declarations, >etc., are not comma operators, and do not guarantee left to right evaluation." > >In this case the arguments may be evaluated in parallel. It'll be interesting >to see if i is printed as the last variable in the same print statment, will >it be 0. #include int a [3]; main() { int i; a[0] = 5; a[1] = 6; a[2] = 7; i = 0; printf("%d %d %d\n", a[++i], a[++i], i); printf("%d\n", i); } output: 7 7 2 2 (output with - printf("%d %d %d\n", a[i++], a[i++], i); - was 5 5 0) Hyuk, Hyuk, Hyuk.... 240GTX / 3.3 / mips version 2.0 >______________ >Nong Tarlton >Microelectonics and Computer Technology Corporation >nong@mcc.com John R. Murray | "They call me Mr. Know-it-all, I am so eloquent. murray@vs2.scri.fsu.edu | Perfection is my middle name! | ...and whatever rhymes with 'eloquent'." - Primus