Content deleted Content added
Stevebroshar (talk | contribs) →Operator precedence: I think the reader is smart enough to know that what follows is a table ;) |
Stevebroshar (talk | contribs) →Operator precedence: More cohesive paragraph wording |
||
Line 446:
==Operator precedence==
During expression evaluation, the order in which sub-expressions are evaluated is determined by [[order of operations|precedence]] and [[operator associativity|associativity]]. An operator with higher precedence is evaluated before a operator of lower precedence and the operands of an operator are evaluated based on associativity. The following table describes the precedence and associativity of the C and C++ operators. Operators are shown in groups of equal precedence with groups ordered in descending precedence from top to bottom.
The syntax of expressions in C and C++ is specified by a [[phrase structure grammar]].<ref>{{cite book | title = ISO/IEC 9899:201x Programming Languages - C | date = 19 December 2011 | publisher = open-std.org – The C Standards Committee | pages = 465}}</ref> The table given here has been inferred from the grammar.{{Citation needed| date = January 2009}} For the ISO C 1999 standard, section 6.5.6 note 71 states that the C grammar provided by the specification defines the precedence of the C operators, and also states that the operator precedence resulting from the grammar closely follows the specification's section ordering:
Line 453:
A precedence table, while mostly adequate, cannot resolve a few details. In particular, note that the [[ternary operator]] allows any arbitrary expression as its middle operand, despite being listed as having higher precedence than the assignment and comma operators. Thus <code>a ? b, c : d</code> is interpreted as <code>a ? (b, c) : d</code>, and not as the meaningless <code>(a ? b), (c : d)</code>. So, the expression in the middle of the conditional operator (between <code>'''?'''</code> and <code>''':'''</code>) is parsed as if parenthesized. Also, note that the immediate, unparenthesized result of a C cast expression cannot be the operand of <code>sizeof</code>. Therefore, <code>sizeof (int) * x</code> is interpreted as <code>(sizeof(int)) * x</code> and not <code>sizeof ((int) * x)</code>.
Operator precedence is not affected by overloading.
{| class="wikitable"
|