char 总共8字节,char a;
a = 0xFF; a=1111 1111;其中第一个1为符号位。实际上a=-1;
#2
0xFF和0xFFu不是一回事。
常量也有类型:
C++ Integer Constants
Integer constants are constant data elements that have no fractional parts or exponents. They always begin with a digit. You can specify integer constants in decimal, octal, or hexadecimal form. They can specify signed or unsigned types and long or short types.
To specify integer constants using octal or hexadecimal notation, use a prefix that denotes the base. To specify an integer constant of a given integral type, use a suffix that denotes the type.
To specify a decimal constant, begin the specification with a nonzero digit. For example:
int i = 157; // Decimal constant
int j = 0198; // Not a decimal number; erroneous octal constant
int k = 0365; // Leading zero specifies octal constant, not decimal
To specify an octal constant, begin the specification with 0, followed by a sequence of digits in the range 0 through 7. The digits 8 and 9 are errors in specifying an octal constant. For example:
int i = 0377; // Octal constant
int j = 0397; // Error: 9 is not an octal digit
To specify a hexadecimal constant, begin the specification with 0x or 0X (the case of the “x” does not matter), followed by a sequence of digits in the range 0 through 9 and a (or A) through f (or F). Hexadecimal digits a (or A) through f (or F) represent values in the range 10 through 15. For example:
int i = 0x3fff; // Hexadecimal constant
int j = 0X3FFF; // Equal to i
To specify an unsigned type, use either the u or U suffix. To specify a long type, use either the l or L suffix. For example:
unsigned uVal = 328u; // Unsigned value
long lVal = 0x7FFFFFL; // Long value specified
// as hex constant
unsigned long ulVal = 0776745ul; // Unsigned long value
char 总共8字节,char a;
a = 0xFF; a=1111 1111;其中第一个1为符号位。实际上a=-1;
#2
0xFF和0xFFu不是一回事。
常量也有类型:
C++ Integer Constants
Integer constants are constant data elements that have no fractional parts or exponents. They always begin with a digit. You can specify integer constants in decimal, octal, or hexadecimal form. They can specify signed or unsigned types and long or short types.
To specify integer constants using octal or hexadecimal notation, use a prefix that denotes the base. To specify an integer constant of a given integral type, use a suffix that denotes the type.
To specify a decimal constant, begin the specification with a nonzero digit. For example:
int i = 157; // Decimal constant
int j = 0198; // Not a decimal number; erroneous octal constant
int k = 0365; // Leading zero specifies octal constant, not decimal
To specify an octal constant, begin the specification with 0, followed by a sequence of digits in the range 0 through 7. The digits 8 and 9 are errors in specifying an octal constant. For example:
int i = 0377; // Octal constant
int j = 0397; // Error: 9 is not an octal digit
To specify a hexadecimal constant, begin the specification with 0x or 0X (the case of the “x” does not matter), followed by a sequence of digits in the range 0 through 9 and a (or A) through f (or F). Hexadecimal digits a (or A) through f (or F) represent values in the range 10 through 15. For example:
int i = 0x3fff; // Hexadecimal constant
int j = 0X3FFF; // Equal to i
To specify an unsigned type, use either the u or U suffix. To specify a long type, use either the l or L suffix. For example:
unsigned uVal = 328u; // Unsigned value
long lVal = 0x7FFFFFL; // Long value specified
// as hex constant
unsigned long ulVal = 0776745ul; // Unsigned long value
常量也有类型:
C++ Integer Constants
Integer constants are constant data elements that have no fractional parts or exponents. They always begin with a digit. You can specify integer constants in decimal, octal, or hexadecimal form. They can specify signed or unsigned types and long or short types.
To specify integer constants using octal or hexadecimal notation, use a prefix that denotes the base. To specify an integer constant of a given integral type, use a suffix that denotes the type.
To specify a decimal constant, begin the specification with a nonzero digit. For example:
int i = 157; // Decimal constant
int j = 0198; // Not a decimal number; erroneous octal constant
int k = 0365; // Leading zero specifies octal constant, not decimal
To specify an octal constant, begin the specification with 0, followed by a sequence of digits in the range 0 through 7. The digits 8 and 9 are errors in specifying an octal constant. For example:
int i = 0377; // Octal constant
int j = 0397; // Error: 9 is not an octal digit
To specify a hexadecimal constant, begin the specification with 0x or 0X (the case of the “x” does not matter), followed by a sequence of digits in the range 0 through 9 and a (or A) through f (or F). Hexadecimal digits a (or A) through f (or F) represent values in the range 10 through 15. For example:
int i = 0x3fff; // Hexadecimal constant
int j = 0X3FFF; // Equal to i
To specify an unsigned type, use either the u or U suffix. To specify a long type, use either the l or L suffix. For example:
unsigned uVal = 328u; // Unsigned value
long lVal = 0x7FFFFFL; // Long value specified
// as hex constant
unsigned long ulVal = 0776745ul; // Unsigned long value