Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - The difference between integer constants and real constants
The difference between integer constants and real constants
1. Different data types: the default data type of integer constants is int, that is, signed integers. The default type of floating-point constants is double, that is, double-precision type.

Second, the storage methods are different: integer data is stored in the computer with complement, and real data is stored in IEEE754 standard.

Third, different expressions: integer constants In C language, integer constants are divided into three forms: decimal integer constants, octal integer constants and hexadecimal integer constants. There are two representations of real constants: one is decimal form, and the other is exponential form.

Extended data

Integer constants In C language, integer constants are expressed in decimal, octal and hexadecimal forms.

1, decimal integer constant

The representation of decimal integer constants is the same as that in mathematics. Decimal integer constants consist of numbers from 0 to 9 without prefix.

2. Octal integer constant

The expression of octal integer constant begins with the number 0, which is the prefix of octal number and consists of numbers from 0 to 7.

3. Hexadecimal integer constant

The expression of hexadecimal integer constant is prefixed with 0X or 0x and consists of numbers 0~9, letters A~F or a ~ f.

Note: In the program, various binary numbers are distinguished by prefixes. So when writing constants, don't get the prefix wrong, which will lead to incorrect results.

In addition, integer constants are divided into short integer and long integer according to their length (suffix is lowercase letter L or uppercase letter L), among which short integer is the default, such as 377 is short integer and 377l or 377L is long integer.

Real number constants In C language, real number constants can only be expressed in decimal. It has two forms: decimal form and exponential form.

1, decimal form

It consists of symbols, numbers from 0 to 9 and decimal points. There cannot be numbers before and after the decimal point (it cannot be omitted at the same time). Such as:-1.85, 0.24, .426,-1 1.

2. Exponential form

It consists of decimal number plus rank code mark e or e and rank code. Its general form is aEn. Where a is a decimal number, n is a decimal integer ("+"can be omitted when n is a positive number), and its value is a× 10? .

For example, 1.236e+2 means1.236x10? .

References:

Baidu Encyclopedia-Integer Constant

Baidu Encyclopedia-Real Constant