in reply to Re: post-increment/pre-increment blues
in thread post-increment/pre-increment blues

print ++$i + $i++ + 1;

Entering this line with i==5 prints (6+7+1) or (7+6+1). Sooo ++ has higher precedence than +. Certainly fun, but really not so hard to figure out why 14, eh?

Replies are listed 'Best First'.
Re: To get 14...
by Abigail-II (Bishop) on Jun 19, 2002 at 16:34 UTC
    ++ has higher precedence than +, but that's irrelevant. Precedence only determines how things are parsed. It does not determine the order of evaluation.

    As pointed out to people before, the value of the expression ++$i + $i++ + 1 is undefined. Any reasoning about what the value would be is a futile exercise. Any answer is as good (or wrong) as any other.

    Abigail