溪边树

象一棵树,栽在溪水旁。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Common Programming Errors -- Chapter 4

Posted on 2010-01-21 16:15  溪边树  阅读(155)  评论(0编辑  收藏  举报

All the following words are from the book "C++ How to Program, Fifth Edition", H.M. Deitel. Any commercial using is firmly denied.

Common Programming Errors 4.1

Not providing, in the body of a while statement, an action that eventually causes the condition in the while to become false normally results in a logic error called an infinite loop, in which the repetition statement never terminates. This can make a program appear to "hang" or "freeze" if the loop body does not contain statements that interact with the user.

Common Programming Errors 4.2

Not initializing counters and totals can lead to logic errors. Initialize each counter and total, either in its declaration or in an assignment statement. Totals are normally initialized to 0.

Common Programming Errors 4.3

Using a loop's counter-control variable in a calculation after the loop often causes a common logic error called an off-by-one-error. In a counter-controlled that counts up by one each time through the loop, the loop terminates when the counter's value is one higher than its last legitimate value (i.e. 11 in the case of couting from 1 to 10).

Common Programming Errors 4.4

Using floating-point numbers in a manner that assumes they are represented exactly (e.g. using them in comparisons for equality) can lead to incorrect results. Floating-point numbers are represented only approximately by most computers. For further reading about floating-point numbers, pleas refer to: /Files/furaibo/定点数和浮点数.pdf

Attempting to use the increment or decrement operator on an expression other than a modifiable variable name or reference, e.g. writing ++(x + 1), is a syntax error.