int and larger values are type long. By adding a suffix, we can force the type of a literal integer constant to be type long or unsigned or unsigned long. We specify that a constant is a long by immediately following the value with either L or l (the letter “ell” in either uppercase or lowercase).
根据语法, 八进制或十六进制的整数字面常量有可能是unsigned 类型(unsigned int 或unsignedlong),而十进制的整数字面常量只能是int 或long 类型。不过代码中还是直接以后缀标明类型为佳。
When specifying a long, use the uppercase L: the lowercase letter l is too easily mistaken for the digit 1.
In a similar manner, we can specify unsigned by following the literal with either U or u. We can obtain an unsigned long literal constant by following the value by both L and U. The suffix must appear with no intervening space:
- 128u /* unsigned */ 1024UL /* unsigned long */
- 1L /* long */ 8Lu /* unsigned long */
There are no literals of type short.
注意:整数字面常量没有负数,代码中出现的形如“-1”的数是个表达式,表示1 这个字面常量的相反数(详见第5.1 节:一元取反操作符)。
Rules for Floating-Point Literals
We can use either common decimal notation or scientific notation to write floatingpoint literal constants. Using scientific notation, the exponent is indicated either by E or e. By default, floating-point literals are type double. We indicate single
precision by following the value with either F or f. Similarly, we specify extended precision by following the value with either L or l (again, use of the lowercase l is discouraged). Each pair of literals below denote the same underlying value:
3.14159F .001f 12.345L 0.
3.14159E0f 1E-3F 1.2345E1L 0e0
Boolean and Character Literals
The words true and false are literals of type bool:
- bool test = false;
Printable character literals are written by enclosing the character within single quotation marks:
- 'a' '2' ',' ' ' // blank
注意:一对单引号之间只能有一个字符,否则编译器会给出警告。