十一、操作符的次序
Table 3.6. 操作符次序 操作符 描述
++, -- 自增,自減 -, ~, ! 單目 ** 乘方 =~, !~ 模式匹配 *, /, %, x 乘,除,取余,重復(fù) +, -, . 加,減,聯(lián)接 <<, >> 移位 -e, -r, etc. 文件狀態(tài) <, <=, >, >=, lt, le, gt, ge 不等比較 ==, !=, <=>, eq, ne, cmp 相等比較 & 位與 |, ^ 位或,位異或 && 邏輯與 || 邏輯或 .. 列表范圍 ? and : 條件操作符 =, +=, -=, *=, 賦值 and so on , 逗號操作符 not Low-precedence logical NOT and Low-precedence logical AND or, xor Low-precedence logical OR and XOR
.操作符結(jié)合性(associativity):
Table 3.7. 操作符結(jié)合性
操作符 結(jié)合性 ++, -- 無 -, ~, ! Right-to-left ** Right-to-left =~, !~ Left-to-right *, /, %, x Left-to-right +, -, . Left-to-right <<, >> Left-to-right -e, -r, 無 <, <=, >, >=, lt, le, gt, ge Left-to-right ==, !=, <=>, eq, ne, cmp Left-to-right & Left-to-right |, ^ Left-to-right && Left-to-right || Left-to-right .. Left-to-right ? and : Right-to-left =, +=, -=, *=, Right-to-left and so on , Left-to-right not Left-to-right and Left-to-right or, xor Left-to-right
建議: 1、當(dāng)你不確定某操作符是否先執(zhí)行時,一定要用括號明確之。 2、用多行、空格等方式提高程序的可讀性。
|