The type bool represents the truth values, true and false. We can assign any of the arithmetic types to a bool. An arithmetic type with value 0 yields a bool that holds false. Any nonzero value is treated as true.
Signed and Unsigned Types
The integral types, except the boolean type, may be either signed or unsigned. As its name suggests, a signed type can represent both negative and positive numbers Table 2.1: C++(www.cppentry.com): Arithmetic Types (including zero), whereas an unsigned type represents only values greater than or equal to zero.
表2.1 列出的类型中最常用的有四个:int、bool、double、char。本章后文会介绍基本类型的选用规则。
The integers, int, short, and long, are all signed by default. To get an unsigned type, the type must be specified as unsigned, such as unsigned long. The unsigned int type may be abbreviated as unsigned. That is, unsigned with no other type implies unsigned int.
Unlike the other integral types, there are three distinct types for char: plain char, signed char, and unsigned char. Although there are three distinct types, there are only two ways a char can be represented. The char type is respresented using either the signed char or unsigned char version. Which representation is used for char varies by compiler.
这是C++(www.cppentry.com) 语言的一个奇怪之处,char 是否有符号由编译器决定。通常编译器会提供一个选项,用于指明char 是否有符号。