Chapter 2: Data Type, Operator, Expression
The data type of C language is in the first lesson, we have seen the variables used in the program should be pre-explained, that is, first explained, and then used. Description of variables can include three aspects: • Data type · Storage type · Scope In this lesson, we only introduce data type description. Other descriptions are described in the following chapters. The so-called data type is divided by the nature, representation, and the formation of storage space, and the structure characteristics are divided. In C language, the data type can be divided into: basic data type, constructive data type, pointer type, and four categories. 1. Basic data type Basic data types The most important feature is that its value cannot be decomposed into other types. That is, the basic data type is self-description. 2. Construct Data Type Construction Data Types are defined based on the method of constructing with a defined one or more data types. That is, the value of a structure type can be broken down into several "members" or "elements". Each "member" is a basic data type or is another constructor. In the C language, the structure type has the following: • Array type · Structural type · Joint type 3. Pointer type pointer is a special, and it is also a data type with important role. Its value is used to indicate an address in the memory in the memory. Although the value of the pointer variable is similar to the intensive amount, this is the two types of completely different amounts, so it cannot be mixed. 4. Null Type When the function value is called, a function value should usually return to the caller. This returned function value is of a certain data type, which should be given in the function definition and function description, for example, in the Max function definition given in the example, the function head is: int A, INT B) The "int" type specifier indicates that the return value of the function is an integer amount. Another example is in the example, the library function SIN is used. Since the system specifies that its function return value is a double precision floating point type, the value S = sin (x); in, S must also be a double precision floating point force The return value of the SIN function is consistent. So in the explanation section, explain S as a double precision floating point. However, there is also a class of functions. It does not need to return a function value to the caller after calling. This function can be defined as "empty type." Its type specifier is VOID. In detail in the fifth chapter function. In this chapter, we will introduce integer, floating-point and characters in the basic data type. The remaining types will be introduced in the chapters in the chapters. For the basic data type, it is divided into constants and variables according to whether the value can be changed. During the execution of the program, the value of its value does not change is called constant, and the value variable variable is called a variable. They can be classified with data types. For example, it can be divided into integer, integer variable, floating point constant, floating point variable, character constant, character variable, enumeration, enumeration variable. In the program, constants can be directly referenced without explanation, and the variables must be used first.
Integer intensity includes integer constants, integer variables. Integral constants is an integral. In C language, the complete number of use has three kinds of eight-in-one, hexadecimal and decimal. Integral constant 1. Octa-made constant eight-feed immologist must begin with 0, ie 0 as an eight-input prefix. The digital value is 0 ~ 7. The number of octaves is usually unsigned. The following numbers are legal octaves: 015 (decimal 13) 0101 (decimal 65) 0177777 (decimal 65535) The following number is not legal octal number: 256 (unprogin 0) 03A2 (including non-eight-way digital digital) -0127 (there is a negative sign) 2. The prefix of the hexadecimal process of tens of sixteen-entered constants is 0x or 0x. Its digital value is 0 ~ 9, A ~ f or A ~ F. The following numbers are legally hexadecimal impromptus: 0x2a (decimal 42) 0xA0 (decimal 160) 0xFFF (decimal 65535) The following number is not a legal hexadecimal general number: 5A (unproped 0x) 0x3h (containing non-heteo digital digital) 3. Decoction-making constant dozens of progressive constants have no prefix. Its digital is 0 ~ 9. The following numbers are legal decimal usual numbers: 237 -568 65535 1627 The following number is not a legal decimal general number: 023 (not a preamble 0) 23d (including non-ten-way digital) is based on the prefix in the program to distinguish various kinds Counting. Therefore, don't make the prefix correctly when writing constants is incorrect. 4. The suffix of the integer constant is on the 16-bit word long, the basic integer is also 16 bits, so the scope of the number indicated is also limited. The decimal number of endless symbols is from 0 to 65535, and the number of symbols is -32768 ~ 32767. The representation of the octal unsigned number is 0 ~ 0177777. The hexadecimal non-symbolic number of representations is 0x0 ~ 0xFFFF or 0x0 ~ 0xFFFF. If the number of uses exceeds the above range, it must be represented by long integer. Long integer is represented by suffix "L" or "L". For example: decimal length is 158L (decimal 158) 358000L (decimal is -358000) octal long improvement 012L (decimal 10) 077L (decimal 63) 0200000L (decimal 65536) hexadecimal length often 0x15L ( Teconation 21) 0xA5L (decimal 165) 0x10000L (decimal 65536) Long integer 158L and basic completion 158 There is no difference in value. But to 158L, because the C-compilation system will allocate 4 byte storage space for it. For 158, since it is basically integrated, only 2 bytes of storage space is allocated. Therefore, pay attention to the operation and output format, avoid errors. No symbol numbers can also be represented by the suffix, the suffix of unsigned number of integer constants is "U" or "U". For example: 358U, 0x38au, 235lu are both unsigned. Prefix, suffix can be used simultaneously to represent various types of numbers. If 0xA5lu means hexadecimal unsigned long integer A5, its decimal is 165. The integer variable integer variable can be divided into the following categories: 1. The basic type specifier is int, which is 2 bytes in memory, and the value is fundamental. 2. Short INT or SHORT 'C110F1 in the shortity type specifier. All bytes and value ranges are the same as the basic type. 3. Long integer type specifier is long int or long, accounting for 4 bytes in memory, and the value is long and constant. 4. No symbol type Type Description is unsigned. The unsigned type can also be composed of three types of these types: (1) Signature Basic Type Description is unsigned int or unsigned. (2) No symbolic short integer type specifier for unsigned short (3) No symbolic long integer type specifier is the same amount of memory spatial bytes of the number of unsigned types of all kinds of non-symbolic types with the corresponding amount of symbol type . But because the symbol bit is saved, it cannot be represented.
The following table lists the representations of the number of memory by allocation of various types in Turbo C. Type Description Number INT -32768 ~ 32767 ■■ Short Int -32768 ~ 32767 ■ ■ ■ ■■■■■■■■■■ UNSIGNED INT 0 ~ 65535 ■ ■ ■ ■ ■■■ Unsigned long 0 ~ 4294967295 ■■■■ Description Variables for integer variables Description of variables Description: Type Description Variable Name identifier, variable name identifier, ...;, for example: int A, B, C; (A, B, C is integer variable) long x, y; (x, y is long integer variable) Unsigned P, q; (p, q is unsigned integer variable)
When writing variables, you should pay attention to the following points: 1. Allows that multiple of the same types of variables are allowed after a type specifier. Between the variable names are separated by commas. Type indicators are at least one space interval between the variable name. 2. The last variable name must be ended with ";". 3. Variable description must be placed before the variable is used. Generally placed at the beginning of the function body. [Practical] // 1Int A, B; Short Int C; SHORT D = 100; A = D-20; B = A D; C = A B D; D = D-A CB; 'VTAblea, 2,0b, 2,0c, 2,0d, 2,100of vtable'vupdate1,0; 2,03,04,1001,802,1803,3604,200of vupdateof phactice [PractICE] // 2Int a = 5; int b = 9; long d; long d; c = a b-7; d = a * b * c; c = d * d * d; a = cd; 'vTablea, 2,5b, 2,9c, 4, 0D, 4, 0OF VTable'vupdate1, 52, 93, 04, 03, 74, 3153, 312558751, -5112OF VUPDATEOF PRACTICTICE [PractICE] // 3Int a = 6, b = 19; Unsigned Int C; INT D; c = A-B 7; D = B * C; A = B C D; B = -A; 'Vtablea, 2,6b, 2, 19c, 2,0d, 2,0of vtable'vupdate1, 6; 2,193 , 04, 03, 655304, -1141, -1012, 101OF VUPDATEOF PRACTICEVOID Main () {LONG X, Y; INT A, B, C, D; X = 5; Y = 6; A = 7; b = 8; C = x a; d = y b; Printf ("C = x a =% D, D = Y B =% D / N", C, D);} Describe the main description as return Void, ie Do not return any type of value x, y is defined as long-type A, B, C, D is defined as int type 5-> x6-> Y7-> A8-> bx a-> cy b-> D display Procedure Of Long X, Y; INT A, B, C, D; C = X A; D = Y B; From the program you can see: x, y is long integer variable, A, B is Basic integer variable. It is allowed to operate, and the calculation results are long integration. However, C, D are defined as the basic integer, so the last result is basically integrated. In this case, different types of amounts can be involved in the calculation and assign each other. The type conversion is automatically completed by the compilation system. The rules related to type conversion will be described later. Realistic quantity real constant realmage is also known as floating point. Real aspects are also referred to as real or floating point numbers. In the C language, the real numbers only use decimal. It has two forms: decimal form index form 1. Decimal number consists of 0 to 9 and decimal points. For example: 0.0, .25, 5.789, 0.13, 5.0, 300., - 267.8230, etc. are all legal realities. 2. Index form is constructed by decimal number, plus group code flag "e" or "e", and class code (only an integer, can be symbol).
Its general form is A E n (a is a decimal number, n is a decimal integer) its value is A * 10, N as: 2.1e5 (equal to 2.7 * 10), 3.7e-2 (equal to 3.7 * 10,) -2 *) 0.5E7 (equal to 0.5 * 10, 7), -2.8e-2 (equal to -2.8 * 10,) - 2 *) The following is not a legal real number 345 (no small number point) E7 (untaled before the code flag e Numbers) -5 (no marked sign) 53.-E3 (negative position is not) 2.7e (no line) Standard C allows floating point numbers to use suffixes. The suffix is "f" or "f" means that the number is the floating point number. Such as 356f and 356. is equivalent. Example 2.2 illustrates this situation: void main () {Printf ("% f / n% f / n", 356., 356f);} VOID indicates that Main does not return any value to end the real variable real value Variables are divided into two categories: single precision type and double precision type, the type of type specifier is a Float single precision specifier, Double double precision specifier. Single precision type in Turbo C accounts for 4 bytes (32-bit) memory space, and its numerical range is from 3.4e-38 ~ 3.4e 38, only seven valid numbers can only be provided. Double-precision type accounts for 8 bytes (64-bit) memory space, and its numerical range is 1.7e-308 ~ 1.7e 308, which provides 16-bit valid numbers. The format and writing rules illustrated by real variables are identical. For example: float x, y; (x, y is single precision real) Double A, B, C; (A, B, C are double precision real amount) real constant is not divided, double precision, Double precision Double processing. Void main () {float a; double b; a = 33333.33333; b = 333333333333333333333; Printf ("% f / n% f / n", a, b);} This program shows different A ■■■ ■ b ■■■■■■■■ 1333333333; This example can be seen that since A is a single precision floating point, the number of effective bits is only seven. The integer has five digits, so the decimal two is the invalid number. B is a double-precision type, a valid bit is a sixteen. However, Turbo C regulates up to six times after the decimation, and the rest is rounded. [Practical] // floatint a = 32; float b; double d; b = 12345678; D = B * 100; D = D a; D = D 58.123456; 'Vtablea, 2,32b, 4, 0.0d, 8,0.0of Vtable'Vupdate1,322,03,02,12345678.000003,12345678003,12345678323,1234567890.123456of Vupdateof Practice [Practice] // 1int a = 543; float b; b = 123.123962 a; b = b-100; a = B; 'Vtablea, 2,543b, 4,0.0of vtable'vupdate1,5432,0.02,123.1239622,23.1239621,23of vupdateof phactice characters
The character model includes character constants and character variables. Character constant characters constant is a character enclosed in single quotes. For example, 'a', 'b', '=', ' ', '?' Is all legitimate character constants. In C language, character constants have the following characteristics: 1. Character constants can only be enclosed in single quotes, and cannot be used in double quotes or other parentheses. 2. Character constants can only be single characters and cannot be a string. 3. The character can be any character in the character set. But numbers cannot participate in numerical operations after they are defined as characters. For example, '5' and 5 are different. '5' is a character constant and cannot participate in the operation. Essential character escape characters is a special character constant. The escape character begins with a backslash "/", followed by one or a few characters. The escape character has a specific meaning, different from the original meaning of characters, so that "escape" characters. For example, "/ n" used in the format string of the previous example Printf function is a escape character, and its meaning is "Enter the Running Wrap". The escape character is primarily used to indicate those control code that is inconvenient to use in general characters. Common escape character and its meaning of its meaning / emission character escape character / n Enter-in-line / T lateral jump to the next table list / v vertical jumping Ground / B retracted / R Enter / f Pass Page // Antilancing "/" / 'Single Number / A ring / DDD 1 ~ 3 bits of the character / XHH 1 ~ 2 hexadecimal speech representatives represent the characters represented by the number, Any character set in the C language character can be represented by a escape character. The / DDD and / XHH in Table 2.2 is proposed for this purpose. DDD and HH are an octal and hexadecimal ASCII code. Such as / 101 denotes the word? Quot; a ", / 102 indicates that the alphabet" B ", / 134 indicates the anti-slope, / XOA means a wrap, or the like. Use Void main () {INT A, B, C; A = 5; B = 6; C = 7; Printf ("% D / N / T% D% D / N% D% D / T / B% D / N", A, B, C, A, B, c);} This program practice the use of essential characters A, B, C as integers 5-> a, 6-> b, 7-> C calls the Printf display program running result printf ("% D / N / T% D % d / n% D% d / t / b% d / n ", A, B, C, A, B, C); the program is" / N "after the first column output A value 5, so the carriage return Waiting; then it is "/ t", so it jumps to the next table position (set the interval between the table positions), then output B value 6; the empty diques and then outputting the C value 7 after it is "/ n", Therefore, then return to the train; then output a value 5 after the second; then the value of the three-color and output B is 6; "/ t" is jumped to the next table position (6 alignment with the previous line), However, the next escape character "/ b" is returned, so the 6th output C value 7. The value of the character variable character variable is the character constant, the single character. Type of character variable Description is char The format and writing rules illustrated by the character variable type are the same as the integer variable. For example: CHAR A, B; each character variable is assigned a byte memory space, so only one character can be stored. The character value is ascii code The form is stored in the memory cell of the variable. For example, the decimal ASCII code is 120, Y's decimal ASCII code is 121.
The character variables a, b gives 'x' and 'y' values: a = 'x'; b = 'y'; actually stores the binary code of 120 and 121 in two cells in A, B: A 0 1 1 1 1 0 0 0 B 0 1 1 1 1 0 0 1 So it can also be regarded as an integer amount. The C language allows the integer variable to be assigned, and the character variable is allowed to be integrated. At the time of output, the character variable is allowed to output the character variable, which is also allowed to output an integer to the character amount. The total amount is two-word output, the character amount is single-word output, and when the integer amount is processed by the characterization amount, only low eight bytes are involved in processing. Main () {Char A, B; A = 120; B = 121; Printf ("% C,% C / N% D,% D / N", A, B, A, B);} a ■ b ■ A <- 120B <--- 121 Display Procedure CHAR A, B; A = 120; B = 121; In this app, a, b is a character type, but assigns an integer value in the assignment statement. From the results, the output form of the A and B values depends on the formatter in the Printf function format string. When the format is "c", the corresponding output variable value is character, and when the format is "D", the corresponding output The variable value is integer. Void main () {char A, b; a = 'x'; b = 'y'; A = a-32; b = b-32; Printf ("% C,% C / N% D,% D / N ", A, B, A, B);} A, B is illustrated as character variables and gives a character value to change lowercase letters to uppercase letters in integer and character output this example, A, B is illustrated as characters Variables and give character values, C language allows character variables to participate in numerical calculations, ie, with characters, ASCII, and participate in operations. Since the ASCII code of the uppercase letter is different from 32, the lowercase letters are changed to uppercase letters after operation. Then output in integer and characteristic, respectively. [Practical] // Charint A = 49; Char B; Char D; B = A 10; D = A B; 'VTAblea, 2,49b, 1, random D, 1, Random Of vtable'vupdate1,492, Random 3, random 2, ';' 3, 'l'of vupdateof phactice [Practice] // CHAR C1, C2; C1 =' a '; C2 =' b '; C1 = C1-32; C2 = C2-32 'VTableC1, 1, random C2, 1, random Of vTable'vupdate1, random; 2, random 1,' a '; 2,' b'1, 'a'; 2, 'b'OF VUPDATEOF PRACTICE String Region String constant is a character sequence enclosed by a pair of double quotes. For example: "China", "C Program:," $ 12.5 "is all legitimate string constants. String constants and character constants are different. They have the following differences between them: 1. Character constants Get up, string constants are enclosed by double quotes .2. Character constants can only be single characters, string constants can contain one or more characters .3. You can give a character constant to a character variable, but you can't put a character CRRAMS is given a character variable. There is no corresponding string variable in the C language. This is different from the BASIC language. But you can use a character array to store a string constant. In the chapter chapter, it is introduced. 4. Character Constants account for a byte memory space. The number of memory bytes of the string constant is equal to the number of bytes in the string 1.
The result is stored in one byte (ASCII code is 0). This is the symbol of the end of the string. For example, the byte of the string "C Program" in memory is: c Program / 0. Character constants 'a' and string constance "a" although there is only one character, the situation in memory is different. 'a' is a byte in memory, which can be represented as: a "a" accounts for two bytes in memory, which can be represented as: A / 0 symbol constant symbol constant in the C language, you can use an identifier Represents a constant called symbol constant. The symbol constant must be defined before use, and its general form is: #define identifier constant where #define is also a preprocess command (pre-processing commands, quot; # "starting), called macro definition command (in Chapter 9 Further introduction will be further described in the pretreatment program) that the function is to define the identifier as the subsequent constant value. Once defined, the place in the program in the program is in this constant value. Habit symbol constant The identifier is used in uppercase letters, the variable identifier with lowercase letters, with the difference. # Define pi 3.14159void main () {float s, r; r = 5; s = pi * r * r; printf ("s =% f / n ", s);} Definition PI is 3.14159 S, R is defined as real estimation 5-> r pi * r * r-> s display procedure FLOAT S, R; R = 5; s = Pi * r * r; This program defines the PI 3.14159 before the main function, in the program, in this value instead of Pi .s = pi * r * r is equivalent to S = 3.14159 * r * r. should pay attention It is that the symbol constant is not a variable, and the value it represents cannot change in the entire scope. That is, in the program, it cannot re-assipulate it with the assignment statement. The initial value of the variable and the type conversion variable In the program, the variable is often required to use the variable. There are a variety of methods in the language program. This method is referred to as an initialization in the definition, and this method is called initialization. Form is: Type Description Variable 1 = Value 1, Variable 2 = Value 2, ...;, for example: int a = b = c = 5; float x = 3.2, y = 3F, z = 0.75; char CH1 = 'K ', CH2 =' p '; should note that continuous assignment is not allowed in the description, such as a = b = c = 5 is illegal .void main () {INT A = 3, B, c = 5; b = A C; Printf ("A =% D, B =% D, C =% D / N", A, B, C);} a <--- 3, b <- 0, c <- -5B <- A C Display Procedure Run Result Variable The data type of converted variables can be converted. There are two ways to convert, one is an automatic conversion. One is forced conversion. Automatic conversion automatic conversion occurs When the amount of different data types is mixed, the compilation system is automatically complete. Automatic conversion follows the following rules: 1. If the participation of the amount of operation is different, first convert to the same type, and then operate. 2. Conversion is increased by data length The direction is performed to ensure that the accuracy does not decrease. If the INT type and long type operation, the int quantity is then converted to the LONG type.
3. All floating point operations are carried out in double precision, even if only the expression of the Float single-intensity metrics, you must first turn into a Double type, and then operate. 4. CHAR type and short type participate in the operation, it must be converted to an INT type. 5. In assignment, the data type of the assignment number is not at the same time, the type of the value of the assignment number will be converted to the type of the left. If the left length of the data type length is long, a part of the data will be lost, which will reduce the accuracy, and the lost part is rounded forward. Figure 21 shows the rules for type automatic conversion. Void main () {float pi = 3.14159; INT S, R = 5; s = r * r * pi; printf ("s =% d / n", s);} Pi <- 3.14159s <- 0 , R <- 5S <- r * r * pi display procedure run results float pi = 3.14159; INT S, R = 5; s = r * r * pi; in this case, PI is a real shape; s, r is integer. R and Pi are converted to Double type calculations when performing S = R * R * PI statement, and the result is also Double type. However, since S is integer, the result is still intellectual, and the fractional part is went.
Forced type conversion mandatory type conversion is achieved by a type conversion operation. Its general form is: (Type Description) (Expression) The function is to convert the calculation result of the expression to the type represented by the type of description. For example: (float) A converts A converted to realistic (int) (x y) to convert the results of X Y to integer when using forced conversion: 1. Type indicators and expressions must Add parentheses (single variables may not be bordered), such as writing (IN Y) (int) x y, it is added to Y after converting X and Y. 2. Whether it is forced conversion or auto-conversion, it is only a temporary conversion of the data length of the variable for the need for this operation, without changing the type of variable. Main () {float f = 5.75; Printf ("(int) f =% D, f =% f / n", (int) f, f);} f <- 5.75 convert FLOAT F to INT F Float f = 5.75; Printf ("" f =% D, f =% f / n ", (int) f, f); this example shows that although f is forced to convert to int type, only in operation The role is temporary, and the type of F itself does not change. Therefore, the value of (int) f is 5 (deleted decimal) and the value of F is still 5.75. The basic operator and the species of the expression operator, the number of operators and expressions in the conjunctional C language are much less, and there is rare in advanced languages. It is rich operators and expressions to make C language function is very perfect. This is also one of the main features of the C language. The C language operator does not only have different priorities, but also a feature is its combination. In the expression, the order of operations participating in the calculation is not only necessary to comply with the operator priority, but also restrictively restrict the integration of the operator to determine whether it is from left to right or to the left. This binding is not there, thereby also increased the complexity of C language in other advanced languages. The operator's type C language operator can be divided into the following categories: 1. Arithmetic operator is used for all kinds of numerical operations. Including plus ( ), minus (-), multiplied (*), except (/), resufficient (or modeling operation,%), self-increasing ( ), self-reduced (-) a total of seven. 2. The relationship operator is used to compare the operation. Including greater than (>), less than (<), equal to (==), is greater than or equal to (<=), and is equal to six in (! =). 3. Logic operators are used for logical operations. Includes three kinds of (&&), or (||), not (!). 4. The bit operation operator is involved in the amount of calculation, and according to the binary position. Including bit and (&), bit or (|), bit is not (~), bit or (^), left shift (<<), and right (>>). 5. Assignment operator is used to assign value, divided into simple assignment (=), composite arithmetic assignment ( =, - =, * =, / =,% =) and composite operation assignment (& =, | =, ^ =, >> =, << =) The three types of total is 11. 6. Conditional operator This is a three-mean operator for condition evaluation (? :). 7. The comma operator is used to combine several expressions into an expression (,). 8. The pointer operator is used to take content (*) and the address (&) two operations. 9. Ask bytes to calculate the number of bytes accounted for data types (SIZEOF). 10. Special operators include bracket (), subscript [], member (→ ,.) and other kinds. In the priority and binding C language, the operator's operation priority is divided into 15 levels. Level 1, the lowest level 15. In the expression, the priority is higher than the lower priority.
When the operator priority on both sides of an operation is the same, the bonding direction specified by the combination of the operator is treated. The combination of each operator in the C language is divided into two, ie left bonding (from left to right) and right binding (from right to left). For example, the combination of the arithmetic operator is from left to right, that is, the left and right. If there is an expression X-Y Z, Y should be combined with "-", execute the X-Y operation, and then execute the z. This binding direction from left to right is called "left binding". The binding direction from right to left is called "right binding". The most typical right binding operator is an assignment operator. Such as x = y = z, due to the right binding of "=", Y = Z is executed first, and the X = (y = z) operation is performed. There are many of the C language operators for the right binding, and they should be considered to avoid understanding errors. Arithmetic operators and arithmetic expressions Basic arithmetic operators 1. The addition operator " " addition operator is a binocular operator, that is, there should be two quantities to participate in the addition. Such as A B, 4 8, etc. Have right binding. 2. The subtraction operator "-" The subtract operator is a binocular operator. However, "-" can also be used as a negative operator, at this time, the single-grade operation, such as -X, -5, and the like have left bonding. 3. Multiplication operator "*" binocular operation with left conjunction. 4. Separate operators "/" binding have left bonding. When the amount of participation is integrated, the results are also intellectual, and the decimal is went. If there is a real shape in the calculation, the result is a double precision. Void main () {Printf ("/ N / N% D,% D / N", 20/7, -20 / 7); Printf ("% f,% f / n", 20.0 / 7, -20.0 / 7);} The binocular operation has left bonding. When the amount of participation is integrated, the results are also intellectual, and the decimal is went. If there is a real shape in the calculation, the result is a double precision. Printf ("/ N / N% D,% D / N", 20/7, -20 / 7); Printf ("% f,% f / n", 20.0 / 7, -20.0 / 7); this example The results of 20/7, -20 / 7 are all integrated, and the decimal is all right. 20.0 / 7 and -20.0 / 7 is also a real shape due to a real number of participation. 5. Exercise the operator (the model operator) "%" binocular operation with left bonding. The amount involved in the participation is integrated. The result of the remaining operation is equal to the remainder of the two times. Void main () {Printf ("% d / n", 100% 3);} Both the binoculant, with left conjunction. The expense operator is required to participate in the amount of operations. This example output 100 divides the remaining number 1 obtained by 3. Self-increasing 1, the self-reduction 1 operator self-increment 1 operator is " ", and its function is to increase the value of the variable 1. The self-reduction 1 operator is "-", and its function is to make the variable value from 1. Self-increasing 1, the self-reduction 1 operator is single-grade operation, all have a right binding. There are several forms: i i is added to other calculations after it is incremented. - I then participate in other calculations after the reduction of 1. When I i is involved in the operation, the value of i is again increased. I - i After the operation, the value of i is reduced by 1. It is prone to i and i-i-in understanding and use. Especially when they are in a more complex expression or statement, it is often difficult to clarify and should be carefully analyzed.
Void main () {INT i = 8; Printf ("% d / n", i); Printf ("% d / n", - i); Printf ("% d / n", i ); Printf ("% d / n", i -); printf ("% d / n", - i ); Printf ("% d / n", - i - i -);} i <- 8i <- -i 1i <- i-1i <- i 1i <- i-1 I = 8; Printf ("% D / N", I); Printf ("% d / n", - i); Printf ("% d / n", i ); Printf ("% d / n", i -); printf ("% d / n ", -i ); Printf ("% d / n ", - i - I -); i's initial value of 8 second line i plus 1 post-output is 9; the third line minus 1, the output is 8; The fourth line output i is 8 after 8, then add 1 (9); the 5th line output i is 9 after 9, then reduce 1 (8); the sixth line output -8, add 1 (9); After output -9, then 1 (8) void main () {INT i = 5, J = 5, P, q; P = (i ) (i ) (i ); Q = ( J) ( J) ( J); Printf ("% D,% D,% D,% D", P, Q, I, J);} i <- 5, j <- 5 , P <- 0, q <- 0i i i ---> p, i 1 -> i, i 1 -> i, i 1 -> ij 1-> j , J 1-> J, J 1-> J, J J J-> Q INT I = 5, J = 5, P, Q; P = (i ) (i ) (i ); q = ( j) ( j) ( j); in this program, P = (i ) (i ) (i ) should be understood as three I added, so P value Take 15. Then I will increase from 1 three times equivalent to the final value of I. For Q, q = ( J) ( J) ( J) should be understood as q First from 1, then participate in the operation, because Q Self-increased 1 three times after the value of 8 The three 8 additions and the last value of J is still 8. The arithmetic expression expression is a form that is combined by constants, variables, functions, and operators. An expression has a value and its type, which is equal to the values and types of the results obtained by the expression. The expression evaluation is performed in the order of the priority of the operator and the conjunction. A single constant, variable, and function can be considered as a special example of expression. The arithmetic expression is a form of an arithmetic operator and a parentheses. The following is an example of an arithmetic expression: A B (A * 2) / C (x r) * 8- (A B) / 7 i sin (x) sin (y) ( i) - (j ) (k -) assignment operator and assignment expressions simple assignment operators and expressions, simple assignment operations are "=" . A child connected by "=" is called an assignment expression.
Its general form is: variable = expression, for example: x = a bw = sin (a) sin (b) y = i j assignment function is to calculate the value of the expression to give the left variable. The assignment operator has a right binding. Therefore, A = B = c = 5 can be understood as a = (b = 5)) In other advanced languages, the assignment constitutes a statement called an assignment statement. In C, "=" is defined as an operator, thereby constituting an assignment expression. An inviginable expression can occur if an expression can appear. For example, the bonus x = (a = 5) (b = 8) is legal. Its meaning is to give 5 A, 8 to B, then add A, B, and impart X, so X should be equal to 13. In the C language, an assignment statement can also be configured, and according to the C language, any expression is configured as a statement in its unscissable semicolon. Therefore, as X = 8; a = b = c = 5; all assignment statements, we have used a lot in the previous examples. If the data type on both sides of the assignment is different, the system will automatically perform type conversion, that is, the type of assignment is replaced with the type of the left. Specifically, as follows: 1. The real shape gives an integer, went to the fractional portion. The first example 2.9 has explained this. 2. Integer to the real shape, the value is constant, but will be stored in floating point, that is, increase the fractional portion (the value of the fractional portion is 0). 3. Character type gives an integer, because the character type is one byte, and the integer is two bytes, so the character's ASCII code value is placed in the low output, high eight digits 0.4 The integer gives a character type, only gives the low eight digits to the character. Void main () {Int a, b = 322; float x, y = 8.88; CHAR C1 = 'k', C2; A = Y; X = B; a = C1; C2 = B; Printf ("% D, % F,% D,% C ", A, X, A, C2);} int A, b = 322; float x, y = 8.88; CHAR C1 = 'k', C2; Printf ("% D,% f,% D,% C ", A = Y, X = B, A = C1, C2 = b); this example indicates the rules of the type conversion in the above assignment operation. A is integer, give the real amount Y value 888, only the integer 8. X is a real shape, impart an integer B value 322, and then adds the fractional portion. The character amount C1 is given to a change, and the integer B is given to C2 to take the low eight bits to become a character type (the low eight bits of B is 01000010, i.e., decimal 66, press the ASCII code to correspond to character B). The composite assignment and expression can form a compound assignment before the assignment "=". Such as =, - =, * =, / =,% =, << =, >> =, & =, ^ =, | =. The general form of composite assignment expressions is: variable binocular operator = expression It is equivalent to variable = variable operator expression, for example: A = 5 equivalent to A = A 5 x * = Y 7 equivalent In x = x * (y 7) R% = P is equivalent to R = R% P composite assignment, this way of writing, the beginner may not habred, but it is very beneficial to compile processing, can improve compilation efficiency and quality Higher target code. The comma operator and comma expression in comma operator C language comma "" is also an operator called a comma operator.
Its function is to connect two expressions into an expression called a comma expression. Its general form is: Expression 1, the expression 2 is the value of the two expressions, respectively, and as the value of the expression 2 as the entire comma expression. Void main () {INT A = 2, B = 4, C = 6, x, y; y = (x = a b), (B C); Printf ("Y =% D, x =% D ", y, x);} a <- 2, b <- 4, c <- 6, x <- 0, y <- 0x <- a b, y <--- B In this example, Y is equal to the value of the entire comma expression, that is, the value of the expression 2, X is the value of the first expression. Two points in the comma expression also explain: 1. Expression 1 and Expression 2 in general forms of comma expressions can also be a comma expression. For example: Expression 1, (Expression 2, Expression 3) forms a nested situation. Therefore, the comma expression can be extended to the following form: Expression 1, Expression 2, ... Expression N The value of the entire comma expression is equal to the value of the expression N. 2. Using a comma expression in the program, usually, the value of each expression in which the comma expression is required, and the value of the entire comma expression is not necessarily required. 3. Not a comma expression in all comma, as in variable descriptions, the commas in the function parameter table is only used as a space between each variable.