>表:操作符的优先级和结合性描述优先级结合性操作符++ --Suffix/postfixincrement anddecrementLeft-to-right()Function call[]Array subscripting1Structure and union member accessStructure and union member access through->pointerPrefixincrementand decrementRight-to-++ --left+-Unary plus and minus版权所有@陈暂保留所有权利!~Logical NOTandbitwiseNOT2Cast(type)*Indirection (dereference)&Address-ofsizeofSize-of6
版 权 所 有 © 陈 哲 保 留 所 有 权 利 ➢表:操作符的优先级和结合性 6 优先级 操作符 描述 结合性 1 ++ - Suffix/postfix increment and decrement Left-toright () Function call [] Array subscripting . Structure and union member access -> Structure and union member access through pointer 2 ++ - Prefix increment and decrement Right-toleft + - Unary plus and minus ! ~ Logical NOT and bitwise NOT (type) Cast * Indirection (dereference) & Address-of sizeof Size-of
>表:操作符的优先级和结合性描述优先级操作符结合性3*/%Left-to-Multiplication,division,andremainderright4+-Additionand subtraction5<<V>Bitwiseleftshiftandright shift<<=For relational operators<and≤ respectively6>>=Forrelational operators>and≥respectively7== }=For relational = and respectively8&BitwiseAND9ΛBitwiseXOR(exclusiveor)版权所有@陈暂保留所有权利10一BitwiseOR(inclusiveor)11&&Logical AND1112Logical OR7
版 权 所 有 © 陈 哲 保 留 所 有 权 利 7 优先级 操作符 描述 结合性 3 * / % Multiplication, division, and remainder Left-toright 4 + - Addition and subtraction 5 << >> Bitwise left shift and right shift 6 < <= For relational operators < and ≤ respectively > >= For relational operators > and ≥ respectively 7 == != For relational = and ≠ respectively 8 & Bitwise AND 9 ^ Bitwise XOR (exclusive or) 10 | Bitwise OR (inclusive or) 11 && Logical AND 12 || Logical OR ➢表:操作符的优先级和结合性
>表:操作符的优先级和结合性描述优先级操作符结合性?:13Ternary conditionalRight-to-left=Simpleassignment+=Assignmentbysumanddifference-=*=Assignment by product, quotient, and/=remainder14%=<<=Assignmentbybitwiseleftshiftandrightshift>>=版权所有@陈智保留所有权利&=Assignment bybitwiseAND,XOR,andORI=Left-to15Commaright8
版 权 所 有 © 陈 哲 保 留 所 有 权 利 8 ➢表:操作符的优先级和结合性 优先级 操作符 描述 结合性 13 ?: Ternary conditional Right-toleft 14 = Simple assignment += -= Assignment by sum and difference *= /= %= Assignment by product, quotient, and remainder <<= >>= Assignment by bitwise left shift and right shift &= ^= |= Assignment by bitwise AND, XOR, and OR 15 , Comma Left-toright
>例:用括号标出以下表达式的计算顺序oc>a+b等价于 c>(a+b)°a>b==c 等价于 (a>b)==c。a==b<c 等价于 a==(b<c)°a=b>c 等价于a=(b>c)>最佳实践:在不清楚操作符的优先级时,尽量使用括号,而不是依赖于优先级版权所有@陈普保备所有权利9
版 权 所 有 © 陈 哲 保 留 所 有 权 利 ➢例:用括号标出以下表达式的计算顺序 ◦c>a+b 等价于 c>(a+b) ◦a>b==c 等价于 (a>b)==c ◦a==b<c 等价于 a==(b<c) ◦a=b>c 等价于 a=(b>c) ➢最佳实践:在不清楚操作符的优先级时, 尽量使用括号,而不是依赖于优先级。 9
算术操作符>基本算术操作符:。+:正号操作符(一元操作符)。-:负号操作符(一元操作符)*:乘法操作符/:除法操作符%:求余操作符加法操作符(二元操作符)版权所有@陈暂保留所有权利+:-:减法操作符(二元操作符)10
版权所有© 陈哲保留所有权利 算术操作符 ➢基本算术操作符: ◦ + :正号操作符(一元操作符) ◦ - :负号操作符(一元操作符) ◦ * :乘法操作符 ◦ / :除法操作符 ◦ %:求余操作符 ◦ + :加法操作符(二元操作符) ◦ - :减法操作符(二元操作符) 10