From

xiaoxiao2021-03-06  158

Revenile text Source VC World C Language Classroom

From the perspective of the program process, the program can be divided into three basic structures, namely the sequential structure, branch structure, and loop structure.

The C statement can be divided into the following five categories: 1. Expression statement 2. Function call statement 3. Control statement 4. Composite statement 5. Empty statement

Assigning statement

The assignment statement is an expression statement configured by the assignment expression. Its general form is: variable = expression; the function and characteristics of assignment statements are the same as assignment expressions. It is one of the most useful statements in the program. Note the following points in the use of assignment statements:

1. Since the expression in the right side of the value "=" can also be an assignment expression, the following form variable = (variable = expression); it is established, thereby forming a nested situation. The general form after the development is: variable = variable = ... = expression; for example: a = b = c = D = E = 5; according to the right bondability of the assignment operator, therefore actually equivalent to: E = 5 ; D = E; c = D; b = C; a = b; 2. Note the difference between the variable assignment and assignment statements in the variable description. The initial value to the variable is part of the variable description, and the number of variables after the initial value must still be comma intervals between the other similar variables, and the assignment statement must end with the semicolon. 3. In the variable description, it is not allowed to be assigned to multiple variables to the first value. The following description is wrong: int a = b = c = 5 must be written as int a = 5, b = 5, c = 5; and assignment statements allow continuous assignments 4. Note the difference between assignment expressions and assignment statements. Assignment expressions are an expression that can appear in any place where the expression appears, and the assignment statement cannot be. The following statement is legal: if ((x = y 5)> 0) z = x; the function of the statement is that if the expression x = y 5 is greater than 0 z = x. The following statement is illegal: IF ((x = y 5;)> 0) z = x; because = y 5; is a statement, it cannot appear in the expression.

Data output statement

This section describes the statements that output data to standard output devices display. In the C language, all data input / output is done by the library function. It is therefore all function statements. This section describes the Printf function and the PUTCHAR function. The Printf function printf function is called the format output function, and the last letter f is the meaning of "format". Its function is to display the specified data on the display screen by the format specified by the user. In the first example we have used this function multiple times.

First, the general form of PRINTF function call

The Printf function is a standard library function, its function prototype in the header file "stdio.h". However, as a special case, the stdio.h file must be included before using the Printf function. The general form of the Printf function call is: Printf ("Format Control String", Output List) where the format control string is used to specify the output format. Format control strings can be composed of two format strings and non-format strings. The format string is a string that starts with%, with a variety of format characters in%, to illustrate the type, form, length, and lower number of output data. Such as "% D" means that the "% LD" is output according to the decimal output, "% C" indicates that according to the character output, etc. The discussion will be given later.

Non-format strings are illuminated when the output is displayed, and prompts in the display. Each output item is given in the output list, requiring the format string and each output item to correspond to the number and type. Void main () {INT A = 88, B = 89; Printf ("% D% D / N", A, B); Printf ("% D,% D / N", A, B); Printf (" % C,% C / N ", A, B); Printf (" A =% D, B =% D ", A, B);} a <- 8, b <- 89printf ("% D%) D / N ", A, B); Printf ("% D,% D / N ", A, B); Printf ("% C,% C / N ", A, B); Printf (" A =% D, b =% D ", A, b); the value of A, B is output four times in this example, but due to the different format control strings, the results of the output are different. In the output statement format control string of the fourth line, a space (non-format character) is added between the two formatter% D, so there is a space between the outputs A and B values. The PRINTF statement format of the fifth line is added to the non-format character comma, so there is a comma between the output A and B values. The format string of the sixth line requires the A and B values ​​in accordance with the character type. In the seventh line, in order to prompt the output, the non-format string is added.

Second, format string

The general form of format strings in Turbo C is: [Mark] [Output Minimum Width] [. Precision] [Length] Type of which is optional in wise []. The meaning of each item is as follows: 1. Type type character is used to indicate the type of output data, its formatting character and meaning the following table shows: Indicated format character format character in the output type, output with symbol integers in ten-way form (positive Do not output symbols) o Output unsigned integer (no output prefix O) x in an octazone form (no output prefix OX) U output unsigned integer f in decimal form, output order, Double precision real est 8 output single, double precision real g is shorter output width output single, double precision real number C output a single character S Output string 2. Sign flag characters -, , # Four kinds of spaces, the meaning shown below: Sign Format Character Sign Significance - Results The left alignment, the right edge fill the space output symbol (positive or negative) space output value is timing crown, the crown is Negative number # 无 类 类 类 类;; 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 类 0 类 类 类 类 类 类 类 0 类 类 类 类 类 类 0 类 类 类 类 类 类 0 类 类 类Different points 3. Output minimum width with decimal integers to represent the minimum number of outputs. If the actual number of digits is more than the defined width, then the actual number of digits is output. If the actual number of bits is less than the defined width, it is safer or 0.4. The precision accuracy format is "." Begins, and then following the decimal integer. The meaning of this is: If the number is output, the number of digits is indicated; if the output is the character, the number of output characters is indicated; if the actual number of digits is greater than the defined accuracy, the exceeding portion is cut. 5. The length of the length format is H, L, h indicates that the shorter amount is output, and L is indicated by the long output. Void main () {int a = 15; float b = 138.3576278; Double C = 35648256.3645687; char d = 'p'; Printf ("A =% D,% 5D,% O,% x / N", A, A , a, a); Printf ("B =% F,% LF,% 5.4LF,% E / N", B, B, B, B); Printf ("C =% LF,% F,% 8.4LF / N ", C, C, C); Printf (" D =% C,% 8C / N ", D, D);} a <- 15b <- 138.3576278c <- 35648256.3645687d <- ' P 'main () {Int a = 29; float b = 1243.2341; Double C = 24212345.24232; char c =' H'Printf ("A =% D,% 5D,% O,% x / N", A, A , a, a); Printf ("B =% F,% LF,% 5.4LF,% E / N", B, B, B, B); Printf ("C =% LF,% F,% 8.4LF / N ", C, C, C); Printf (" D =% C,% 8C / N ", D, D);} In this case, the value of the integer variable A is output in four formats, of which "% 5D" requires the output width of 5, and a A value is 15 seconds of two, and three spaces. The value of the real amount B is output in four formats in four formats.

Wherein "% f" and "% LF" format are the same, indicating that the "L" symbol has no effect on the "F" type. "% 5.4LF" specifies that the output width is 5, the accuracy is 4, and the actual length is output, and the number of decimal bits exceeds the 4 digits to be cut. The ninth line output double precision implement, "% 8.4LF" cuts more than 4 digits due to the designated accuracy of 4. The tenth line outputs the character quantity D, where "% BC" specifies that the output width is 8 so that 7 spaces are added before the output character P. Pay attention to a problem when using the Printf function, which is the order in the output table column. Different compilation systems are not necessarily the same, can be left to right, or from right to left. Turbo C is made from right to left. If an example 2.13 rewritten as follows: void main () {INT i = 8; Printf ("% D / N% D / N% D / N% D / N% D / N% D / N", I, - i, i -, i , - i - I - 8);} i <- 8

This program is only changed to the multi-printf statement output compared to Example 2.13. However, it can be seen from the results. Why is the result that the result will be different? Just because the PrintF function is performed from the order in which each quantity in the output table is performed. In the formula, the last "-i-" value is first, the result is -8, and then i is 7 after 1. Then the "-i " item is worth -7, and then I is 8 afterwards. Then, the "I-" item is worth 8, then I will then reduce 1 after 7. Request "i " item 7, then I will increase by 8 after another. Request "--i" item, i first below 1, output, the output value is 7. Finally, the first " i" in the output table column will be obtained. At this time I outputs 8 afterwards. However, it must be noted that although the order sequence is from right to left, but the output order is or from left to right, the resulting result is the output result.

Character output function

PUTCHAR function

The PUTCHAR function is a character output function that is functional to output a single character on the display. Its general form is: PUTCHAR (character variable), for example: PUTCHAR ('a'); output uppercase letters aputchar (x); output character variable x value PUTCHAR ('/ n'); Retracence pair control characters perform control functions, Not displayed on the screen. You must use the file with the file to contain the file: #include #include void main () {char A = 'b', b = 'o', c = 'k'; PUTCHAR (a); PUTCHAR (B); PUTCHAR (B); PUTCHAR (C); PUTCHAR ('/ t'); PUTCHAR (A); PUTCHAR (B); PUTCHAR ('/ n'); PUTCHAR (B); PUTCHAR (C);

转载请注明原文地址:https://www.9cbs.com/read-128459.html

New Post(0)