Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What is an integer?
What is an integer?
An integer constant is an integer constant. In C language, there are three kinds of integer constants: octal, hexadecimal and decimal.

1) Decimal integer constant: Decimal integer constant has no prefix. Its number is 0 ~ 9.

The following numbers are legal decimal integer constants:

237、-568、65535、 1627;

The following numbers are not legal decimal integer constants:

023 (leading 0 is not allowed) and 23D (including non-decimal digits).

In the program, all kinds of decimal numbers are distinguished by prefixes. Therefore, when writing constants, don't get the prefix wrong, which will lead to incorrect results.

2) Octal integer constant: Octal integer constant must start with 0, that is, 0 is the prefix of octal number. Digital value is 0 ~ 7. Octal numbers are usually unsigned numbers.

The following numbers are legal octal numbers:

0 15 (decimal 13), 0 10 1 (decimal 65), 0 17777 (decimal 65535);

The following numbers are not legal octal numbers:

256 (without prefix 0), 03A2 (including non-octal digits), -0 127 (with negative sign).

3) Hexadecimal integer constant: the prefix of hexadecimal integer constant is 0X or 0x. Its numerical values are 0~9, A~F or a ~ f.

The following numbers are legal hexadecimal integer constants:

0X2A (decimal 42), 0XA0 (decimal 160) and 0XFFFF (decimal 65535);

The following numbers are not legal hexadecimal integer constants:

5A (without prefix 0X), 0X3H (including non-hexadecimal digits).

4) Integer constant suffix: On the machine with the word length of 16 bits, the length of the basic integer is also 16 bits, so the range of the number represented is also limited. Decimal unsigned integer constants range from 0 to 65535, and signed numbers range from -32768 to +32767. The range of octal unsigned number is 0 ~ 0 177777. The expression range of hexadecimal unsigned number is 0x0 ~ 0xffff or 0x0 ~ 0xffff. If the number used exceeds the above range, it must be expressed as a long integer. Long integers are denoted by the suffix "l" or "l".

For example:

Decimal long integer constant:

158L (decimal 158) and 358000L (decimal 358000);

Octal long integer constant:

0 12L (decimal 10), 077L (decimal 63) and 0200000L (decimal 65536);

Hexadecimal long integer constant:

0X 15L (decimal 2 1), 0XA5L (decimal 165), 0X 10000L (decimal 65536).

There is no numerical difference between the long integer 158L and the basic integer constant 158. But for 158L, because it is a long integer, the C compiler system will allocate 4 bytes of storage space for it. For 158, because it is a basic integer, only 2 bytes of storage space are allocated. So pay attention to the operation and output format to avoid mistakes.

Unsigned numbers can also be represented by suffixes, and the suffix of unsigned numbers with integer constants is "u" or "u".

For example:

358u, 0x38au and 235lu are all unsigned numbers.

Prefixes and suffixes can be used to represent different types of numbers at the same time. For example, 0XA5Lu represents a hexadecimal unsigned long integer A5, and its decimal number is 165.