Why is $a + ++$a == 2?

All the answers explaining why you get 2 and not 1 are actually wrong. According to the PHP documentation, mixing + and ++ in this manner is undefined behavior, so you could get either 1 or 2. Switching to a different version of PHP may change the result you get, and it would be just … Read more

Operator precedence table for the C programming language

Explanation Prec. denotes operator precedence, where group 1 has the highest precedence and group 17 the lowest. Assoc. denotes operator associativity, where such is applicable. Associativity can be either left-to-right or right-to-left. Sources My ambition with this post is to provide a operator precedence table on-site at Stack Overflow, which is correct and canonical. This … Read more

Logical AND, OR: Is left-to-right evaluation guaranteed?

Yes, it’s guaranteed, otherwise such operators would lose much of their usefulness. Important notice: this is valid only for the builtin && and ||; if some criminal overloads them, they are treated as “regular” overloaded binary operators, so in this case both operands are always evaluated, and in unspecified order as usual. For this reason, … Read more

Is Python’s order of evaluation of function arguments and operands deterministic (+ where is it documented)?

Yes, left to right evaluation order is guaranteed, with the exception of assignments. That’s documented here (py2, py3): Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side. In the following lines, expressions will be evaluated in the arithmetic order of their suffixes: … Read more

Order of execution in constructor initialization list

According to ISO/IEC 14882:2003(E) section 12.6.2: Initialization shall proceed in the following order: First, and only for the constructor of the most derived class as described below, virtual base classes shall be initialized in the order they appear on a depth-first left-to-right traversal of the directed acyclic graph of base classes, where “left-to-right” is the … Read more