Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!ames!ll-xn!husc6!ut-sally!im4u!halley!bc From: bc@halley.UUCP (Bill Crews) Newsgroups: comp.lang.c Subject: Re: Associativity -- what is it? Message-ID: <329@halley.UUCP> Date: 24 Feb 88 02:40:28 GMT References: <226@mccc.UUCP> <224@sdrc.UUCP> <234@mccc.UUCP> Reply-To: bc@halley.UUCP (Bill Crews) Organization: Tandem Computers, Austin, TX Lines: 42 In article <234@mccc.UUCP> pjh@mccc.UUCP (Peter J. Holsberg) writes: >In article <224@sdrc.UUCP> scjones@sdrc.UUCP (Larry Jones) writes: >|In article <226@mccc.UUCP>, pjh@mccc.UUCP (Peter J. Holsberg) writes: >|> >|> x = 3 * i ++; >|> >|> Book says that ++ has a higher precedence than *, and that ++ >|> associates from R->L. That makes me think that ++ should be applied >|> first, but I know it isn't. But ???? >| >|But ++ IS applied first! The key point here is that the RESULT of postfix > ^^^^^^^^^^^^^^^^^ >|++ is the value BEFORE incrementation, not that postfix ++ is somehow deferred > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >|until later. > >Well, that still leaves me confused. If i has the value 7, it is 7 that >is added to 3, so it seems to be that the ++ *is* deferred until later. >Also, ++ has higher precedence than +, so why is the incrementation >delayed until after the current value of i is used? Here is how to think of it. ++ performs two functions. It returns a value, and it has an effect on the variable to which it is applied. If the ++ precedes its operand: it increments the operand it returns the resulting value If the ++ succeeds its operand: it increments the operand it returns the value of the operand prior to the increment The other operators with which you are comparing it have only the functions of returning a value. This makes it confusing. But the act of returning the previous value is quite different from deferring the operator's effect. -bc -- Bill Crews Tandem Computers bc@halley.UUCP Austin, Texas ..!rutgers!im4u!halley!bc (512) 244-8350