5.2 Relational and Logical Operators (3)

2013-10-07 15:23:33 · 作者: · 浏览: 72

EXERCISES SECTION 5.2

Exercise 5.5: Explain when operands are eva luated in the logical AND operator, logical OR operator, and equality operator.

Exercise 5.6: Explain the behavior of the following while condition:

  1. char *cp = "Hello World";  
  2. while (cp && *cp) 

Exercise 5.7: Write the condition for a while loop that would read ints from the standard input and stop when the value read is equal to 42.

Exercise 5.8: Write an expression that tests four values, a, b, c, and d, and ensures that a is greater than b, which is greater than c, which is greater than d.

一般只有在非常底层的编程(www.cppentry.com)中才会用到按位操作符。

我注意到有些初学者过分关注微观(语句级)性能,比方说关心 while(true)和 for(;;) 哪个更快,++i 与i=i+1 哪个更快,i/=16 和 i>>= 4 哪个快,等等。而且受一些过时的教科书的影响,他们往往以为使用位运算代表“高效”,并为此牺牲代码的清晰性。我认为这是很不值得的。