Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!mordor!sri-spam!ames!ptsfa!dmt From: dmt@ptsfa.UUCP (Dave Turner) Newsgroups: comp.lang.c Subject: Re: Associativity -- what is it? Message-ID: <4140@ptsfa.UUCP> Date: 25 Feb 88 01:45:09 GMT References: <226@mccc.UUCP> <224@sdrc.UUCP> <234@mccc.UUCP> <3466@killer.UUCP> Reply-To: dmt@ptsfa.UUCP (Dave Turner) Organization: Pacific * Bell, San Ramon, CA Lines: 34 In article <3466@killer.UUCP> jfh@killer.UUCP (The Beach Bum) writes: >In article <234@mccc.UUCP> pjh@mccc.UUCP (Peter J. Holsberg) writes: > > >pre-fix: ++ X -> (X = X + 1) >post-fix: X ++ -> ((X = X + 1), X - 1) > >Try this: > x = 5; > printf ("3 * x ++ = %d\n", 3 * x ++); > printf ("now x = %d\n", x); > >You should get 15 and 4. I suspect you expected 18 or 16 or something >like that. > I expected to get 15 and 6 (not 4) which is exactly what I got when I tried it. I've always found it to be useful to look at ++x and x++ and say: ++x increment x before using it in another expression in the same statement and x++ use the present value of x in any other expressions in this statement before incrementing x. X in the next statement will have the new value. There's more to be said but the above has been satisfactory for over 11 years. -- Dave Turner 415/542-1299 {ihnp4,lll-crg,qantel,pyramid}!ptsfa!dmt