Integral type Data
Data types without decimal places or indices are called integer data, and integer data can be divided into integer constants and integer variables according to the classification of the methods used. According to the definition or display of the system classification, can be divided into decimal, octal and hexadecimal.
Integral Type Constants
Integer constants are integral data types that are immutable in operations, and you can use decimal, octal, and hexadecimal to describe an integer constant. The decimal integer constant is expressed in the following way:
[plus sign] decimal integer value
The decimal integer value can be one or more decimal digits from 0 to 9, and the 1th digit can be a positive or negative sign, but cannot be 0. Octal integer constants are expressed in the following way:
[Positive and negative sign]x octal integer value
The octal integer value can be one or more octal digits from 0 to 7, and the 1th digit after the positive sign must be 0. Hexadecimal integer constants are expressed in the following way:
[Positive and negative symbol]0x hexadecimal integer value//using lowercase X
[Positive and negative symbol]0x hexadecimal integer value//Use capital X
The 1th digit after the sign must be 0, and the 2nd digit must be a lowercase x or a capital X. Hexadecimal 10~15 are represented by the letter a~f respectively. (for example, Decimal 162, represented by octal as 0242, expressed in decimal notation as 0XA2).
Positive integer constants can omit positive and negative symbols, and negative integer constants must precede the values with a minus sign "-" description. The data type of an integer constant depends on the value itself, and if the constant expression does not use a minus sign, the compiler considers the constant to be an unsigned number. The compiler automatically allocates storage based on the length of an integer constant, and can even assume that the data length of the constant is unlimited. But does not mean that any large data can be processed by C language.
Octal and hexadecimal integer constants are stored in a way that does not differ from the decimal number, except that different representations are used when defining. The storage space length of octal and hexadecimal integer constants is also determined by numeric values and can have negative values.
Integral type variable
The process of naming variables is called "declaration", and the C language stipulates that variables must be declared before they are used. Integer variables are declared with the int modifier, see the following source code.
Main ()
{
int A, C; Declaring an integer variable
unsigned int b; Declaring an unsigned integer variable
A = 15; Assign value to variable a
b = A; Assign a value to a variable B, and a value of B to a
c = a + B; Assign value to variable C, the value of C to the and of A and B
printf ("c =%d\n", c); Output hint string and C's value
}
We can see from the example above that different types of integer data can also be used for arithmetic operations.
floating-point data
Floating-point data, also called real data, is a symbolic real number in decimal notation. The value of the symbol real number includes the integer part, the tail part and the exponent part.
floating-point constants
Some larger values, or numbers with decimal digits and digits, need to be represented by floating-point constants. Floating-point constants are in the form of:
[Positive and negative symbol] [value]. Numerical [E | e [positive sign] value]
Where "numeric" is one or more decimal digits, E or E is an exponential symbol. Before the decimal point is the integer part, after the decimal point is the number of parts, if there is no value after the decimal point, the number of parts can be omitted. After the exponential symbol of the positive and negative symbol modifier index, if it is positive, you can omit the positive and negative symbol. If there is no exponent, the index symbol and its subsequent contents can be omitted. For example, the floating-point constant 2.734E3 is the same as the 3-square meaning of the mathematical expression 2.734 x 10. There must be no blank symbol in floating-point constants. In the case of no explanation, the solid constant is positive. If you represent a negative value, you need to use the minus sign before the constant.
Note: The letter E or E must have a number before it, and E or E must be an integer, such as "E6", "1.414e6.1", ". E7", "E", and so on are illegal exponential forms.
floating-point variable
Floating-point variables are single-precision (float) and double precision (double type). Each floating-point variable should be defined before it is used. As shown in the following example:
float A; Declaring a single-precision floating-point variable
Double b; Declaring double-precision floating-point variables
If a floating-point constant is a double-precision floating-point type, the system intercepts the corresponding number of significant digits when the constant is assigned to a single-precision floating-point variable. As shown in the following example:
float A; Declaring a single-precision floating-point variable
A = 1.23456789; Assign a value to a single-precision floating-point variable
The last two decimal places do not work because float variables can only receive 7-digit valid digits. If a is changed to double, all of the 9 digits above can be received and stored in variable a.