免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: maxxfire
打印 上一主题 下一主题

强制类型转换的优先级是多少? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-09-18 21:48 |只看该作者
原帖由 Godbach 于 2008-9-18 15:53 发表


偶一般都是这样的,记住括号的优先级啊,哈哈

普通括号优先级最高级(与-〉同级 ),且是从左到右结合 ,但强制类型转换的括号优先级是次高级

论坛徽章:
0
12 [报告]
发表于 2008-09-18 22:11 |只看该作者
原帖由 langue 于 2008-9-18 20:47 发表


括号的优先级是最低的。

论坛徽章:
0
13 [报告]
发表于 2008-09-18 23:06 |只看该作者
原帖由 tyc611 于 2008-9-18 22:11 发表



错了,是最高的……

http://www.difranco.net/cop2220/op-prec.htm

论坛徽章:
0
14 [报告]
发表于 2008-09-19 01:58 |只看该作者
原帖由 nicozhou 于 2008-9-18 00:08 发表


作践自己也作践别人


while (*p++ = *q++) 就很好,非要写成 while (*(p++) = *(q++)) 吗?
或者 if (a == b && c != d) 非要写成 if ((a == b) && (c != d)) ?

论坛徽章:
0
15 [报告]
发表于 2008-09-19 06:56 |只看该作者
原帖由 emacsnw 于 2008-9-19 01:58 发表


while (*p++ = *q++) 就很好,非要写成 while (*(p++) = *(q++)) 吗?
或者 if (a == b && c != d) 非要写成 if ((a == b) && (c != d)) ?


此人活杠头,照你这种理论,我a=b+c*d+e*f; 要写成啥样?那么明显的玩意用括号,真是闲的难受。看好别人的意思发言好不好?拜托了。谢谢。

while (*p++ = *q++) 就很好,非要写成 while (*(p++) = *(q++))


啥条件语句?搞清楚一个两个的关系。==?

[ 本帖最后由 mzli 于 2008-9-19 06:57 编辑 ]

论坛徽章:
0
16 [报告]
发表于 2008-09-19 08:31 |只看该作者
其实仔细想想就知道了,标准也是这么定出来的。

论坛徽章:
0
17 [报告]
发表于 2008-09-19 08:50 |只看该作者
原帖由 emacsnw 于 2008-9-19 01:58 发表


while (*p++ = *q++) 就很好,非要写成 while (*(p++) = *(q++)) 吗?
或者 if (a == b && c != d) 非要写成 if ((a == b) && (c != d)) ?


我要投诉你灌水。

另外,你好好去学学编程规范。

论坛徽章:
0
18 [报告]
发表于 2008-09-19 09:59 |只看该作者
原帖由 nicozhou 于 2008-9-18 16:50 发表


我要投诉你灌水。

另外,你好好去学学编程规范。


ft,我灌什么水了?我只是表达了我的看法:过多的括号会影响程序美观。
我又没说该加括号以便更清楚的时候不加。

论坛徽章:
0
19 [报告]
发表于 2008-09-19 12:35 |只看该作者
又是括号。。。。。
清楚明白的时候就不用,容易误会的时候就用。

论坛徽章:
0
20 [报告]
发表于 2008-09-19 13:45 |只看该作者
  
Operator
  
  
Description
  
  
Associativity
  
  
()
  []
  .
  ->
  ++  --
  
  
Parentheses (function call) (see Note 1)
  Brackets (array subscript)
  Member selection via object name
  Member selection via pointer
  Postfix increment/decrement (see Note 2)
  
  
left-to-right
  
  
++  --
  +  -
  !  ~
  (type)
  *
  &
  sizeof
  
  
  
Prefix increment/decrement
  Unary plus/minus
  Logical negation/bitwise complement
  Cast (change type)
  Dereference
  Address
  Determine size in bytes
  
  
right-to-left
  
  
*  /  %
  
  
Multiplication/division/modulus
  
  
left-to-right
  
  
+  -
  
  
Addition/subtraction
  
  
left-to-right
  
  
<<  >>
  
  
Bitwise shift left, Bitwise shift right
  
  
left-to-right
  
  
<  <=
  >  >=
  
  
Relational less than/less than or equal to
  Relational greater than/greater than or equal to
  
  
left-to-right
  
  
==  !=
  
  
Relational is equal to/is not equal to
  
  
left-to-right
  
  
&
  
  
Bitwise AND
  
  
left-to-right
  
  
^
  
  
Bitwise exclusive OR
  
  
left-to-right
  
  
|
  
  
Bitwise inclusive OR
  
  
left-to-right
  
  
&&
  
  
Logical AND
  
  
left-to-right
  
  
||
  
  
Logical OR
  
  
left-to-right
  
  
?:
  
  
Ternary conditional
  
  
right-to-left
  
  
=
  +=  -=
  *=  /=
  %=  &=
  ^=  |=
  <<=  >>=
  
  
Assignment
  Addition/subtraction assignment
  Multiplication/division assignment
  Modulus/bitwise AND assignment
  Bitwise exclusive/inclusive OR assignment
  Bitwise shift left/right assignment
  
  
right-to-left
  
  
,
  
  
Comma (separate expressions)
  
  
left-to-right
  
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP