十一、操作符的次序
table 3.6. 操作符次序
操作符 描述
++, -- 自增,自减
-, ~, ! 单目
** 乘方
=~, !~ 模式匹配
*, /, %, x 乘,除,取余,重复
+, -, . 加,减,联接
<<, >> 移位
-e, -r, etc. 文件状态
<, <=, >, >=, 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
.操作符结合性(associativity):
table 3.7. 操作符结合性
操作符 结合性
++, -- 无
-, ~, ! 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、当你不确定某操作符是否先执行时,一定要用括号明确之。
2、用多行、空格等方式提高程序的可读性。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器