版本1和2间的区别
于2006-06-20 19:24:36修订的的版本1
大小: 1162
编辑: 104
备注:
于2006-06-20 19:55:28修订的的版本2
大小: 1245
编辑: czk
备注:
删除的内容标记成这样。 加入的内容标记成这样。
行号 1: 行号 1:
## page was renamed from Types Operators and Expressions/2.5 Arithmetic Operators

Navigation(slides)

2.5 Arithmetic Operators

The binary arithmetic operators are +, -, *, /, and the modulus operator %. Integer division truncates any fractional part. The expression

   x % y

produces the remainder when x is divided by y, and thus is zero when y divides x exactly. For example, a year is a leap year if it is divisible by 4 but not by 100, except that years divisible by 400 are leap years. Therefore

   if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
       printf("%d is a leap year\n", year);
   else
       printf("%d is not a leap year\n", year);

The % operator cannot be applied to a float or double. The direction of truncation for / and the sign of the result for % are machine-dependent for negative operands, as is the action taken on overflow or underflow.

The binary + and - operators have the same precedence, which is lower than the precedence of *, / and %, which is in turn lower than unary + and -. Arithmetic operators associate left to right.

Table 2.1 at the end of this chapter summarizes precedence and associativity for all operators.

Navigation(siblings)

TCPL/2.05_Arithmetic_Operators (2008-02-23 15:35:51由localhost编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.