>第 16 章 运算符详解>运算符总结>习题

梁海波 soniclr@yahoo.com.cn http://learn.akae.cn/media/ch16s04.html
2009-05-08 11:24:13

习题中
if (i & 0xff == 0)
这句话最好把
i&0xff加上()
不然用gcc会告警[warning: suggest parentheses around comparison in operand of &]
而且在redhat/HPUX/AIX上都无法输出正确数据(gcc编译器)


宋劲杉 songjinshan@akaedu.org
2009-05-10 21:12:06

我这个题是故意这么出的。优先级不对嘛。


尹志伟 zhiweiyin1985@gmail.com
2009-08-23 11:05:08

看到您文章中对于C语言有比较深入的探讨,比如结合性和优先级的问题,实际应用中是大家一定会遇到的问题。
我认为:C语言设计原则可以拿来说说,或者说使用者有必要了解设计者最初就怎么这么定了,但是很多探讨的结果比较复杂,记起来也容易乱,如果应付考试或者变态的题目有意义,实际工程中避免此类问题的处理原则往往很简单,比如序列点的问题:往往要求一行代码只做一件事情。或者结合性的问题:按照期望的计算顺序加括号即可。
之所以有这些规定我觉得也是有意义的,毕竟代码是给人看的,编码时应该做的事情是在完成代码功能的情况下尽量提高可读性嘛。
不知道我说的对不对,期待您的回复!


码匠 code_smtih@sohu.com
2009-09-14 15:25:15

In order to get the result : 0xffff, the parentheses are needed because the precedence of '+' operator is higher than '<<'. So it should be changed into: 
   sum = sum + (1U<<i);

Every time read the book, I always get something new. 

This time this chapter makes me clear about precedence and associativity. I am surprised to find I even didn't know the purpose of the associativity before. How confused was I! You make it clear now. Thank you!


jacky haoxj4302@163.com
2010-01-29 00:53:49

请问老师;关于“16、逗号运算符。左结合”运算符,是不是  int add (int a, int b)这种样子??
如果 int subtracter ( int a,int b)
{return a-b;}
 那么int a=2;
subtracter (a++,a++)..结果等于-1吗?


宋劲杉 songjinshan@gmail.com
2010-02-27 22:06:06

看书不仔细,打回去重看


如果您有建设性意见,哪怕只是纠正一个错别字,也请不吝赐教,您留下的姓名和email将会出现在本书前言的致谢中。再次感谢您的宝贵意见!