Chapter 1 Basic knowledge of C language
[test center 1]C program
A program written in C language is called C language source program, and the suffix of the source program file is ".". c”。 The source program compiles and generates a target file named "obi", and then the target file is connected with various library functions to generate a ". Exe "executable file. C language has two basic structures: sequence structure, selective structure and cyclic structure.
[Test Center 2] Main functions
Also known as the main function, it is the population of C program. Main is followed by a pair of brackets and a pair of curly braces, and the part enclosed by curly braces is called the function body of the main function. A C program starts with the main function and ends with the main function body, regardless of the position of the main function in the whole program. Each program has one and only one main function, and all other functions serve the main function.
[Test Site 3] Storage Form
The computer saves data in binary form in the computer, and the binary consisting of 0 or 1 is called bit (eight bits make up a byte, 1 yte-8 bits). Binary, octal and hexadecimal are converted into decimal by multiplication, and decimal is converted into binary, octal and hexadecimal by division. The location where the data is stored is its address.
[Test Site 4] Precautions
Is a description of the program, which can appear anywhere in the program. Comments start from "/*" to the last "*/",during which the computer will not execute anything, and comments cannot be nested.
[Test Site 5] Writing Format
Every statement must be followed by a semicolon, which is a part of the statement. Multiple statements can be written on one line and one statement can be written on multiple lines.
[Test Point 6] Identifier
Is a valid character sequence to identify the name, which can be understood as a word in C program. The naming rules for identifiers are:
(1) Identifiers can only consist of alphanumeric characters and underscores, and letters are case-sensitive.
(2) The first character of the identifier must be a letter or an underscore, not a number.
C language identifiers are divided into the following three categories.
1 keyword. They have a fixed meaning in the program and cannot be used for other purposes. Such as int, for, switch, etc.
2 predefined identifiers. A predefined identifier with a specific meaning. Such as defineinclude.
3 user identifier. Identifier defined by the user as required. Consistent with naming rules, different from keywords.
[Test Site 7] Constants and Variables
A constant is a quantity whose value cannot be changed during the running of a program. Constants are divided into five types: integer constants, real constants, character constants, character application constants and symbolic constants. The amount whose value can be changed during the running of a program is called a variable. C language has no characters, and uses character arrays to store strings.
[Test Site 8] Integer data
Integer constants have three forms: decimal, octal and hexadecimal, and there is no binary form. Octal integer constant plus pre-derivative 0, hexadecimal constant plus leading x, 8 will not appear in octal constant. Integer variables can be divided into basic integer (int), short integer (shot), long integer (lang) and unsigned integer. Basic integers account for 4 bytes. See page 9 of the textbook for the number of bytes and the range of values occupied by other types of integers.
[Test site 9] Real data
There are two representations of real data: decimal form and exponential form. Master the formula for judging the legality of exponential form: there must be a number before E and an integer after E. Real variables can be divided into float and double, and single-precision takes up four bytes.
[Test center 10] Arithmetic operation
The arithmetic operators * * * have+and * 1%. The remainder operation requires that operands can only be integers. When the operands on both sides of the division operator are integers, the operation result is also integers, that is, the decimal part is discarded.
[test site 1 1] forced type conversion
Converts an operand to the specified type in the form of a (type name) expression, paying attention to the position of parentheses.
[test center 12] allocation
The assignment operator is "=", which is different from the relation equal to "= =". The format of the value expression is: variable name = expression. The left side of the assignment operator must be a variable, and the assignment operation is to assign the value of the expression on the right side of the assignment operator to the variable on the left. Compound assignment operator is an operator that combines arithmetic operator or bit operator with assignment operator, and master the method of transforming compound straightening expression into assignment expression. For example, n= 100 can be converted into rFn+ 100.
[Test site 13] Self-addition and self-subtraction operation
The self-addition operator "++"and the self-subtraction operator "_" are monocular operators, and the operands must be variables. Self-increasing and self-decreasing operations are divided into prefix operation and suffix operation, and the values of their corresponding expressions are different, such as = it+; Equivalent to iii = I+1; And ilti are equivalent to i=i+ 1jFia formula: add before use, add before use, and add before use.
[test site 14] comma operation
Comma operator has the lowest priority, and multiple expressions can be combined into a new expression.
Chapter II Sequence Structure
[test site 1] operators, expressions and statements
Operand plus operator constitutes an expression, and expression plus sign constitutes an expression statement. Operand can be an expression. Constant variables such as assignment operators and operands form assignment expressions, and adding symbols to assignment expressions can also form assignment statements.
Priority and combination order of [test site 2] operators
According to the number of objects involved in the operation, operators can be divided into monocular operators, binocular operators and tricular operators. Elementary operators have the highest priority, followed by monocular operators, arithmetic operators, relational operators and logical operators (except logical operators! ), conditional operator, assignment operator, comma operator. The precedence of bit operators is between arithmetic operators and logical operators. The order of combination is mostly from left to right, and there are three kinds from right to left: monocular operator, conditional operator and assignment operator.
[Test site 3] printf function
The format is: printf (output control, output list). The output control is enclosed in a pair of double quotation marks, including the format description and the original content.
Information. The output list contains several output items.
[Test Site 4] format is described in 4]printf function.
% represents an integer. % f stands for single precision real number type% stands for character type% stands for octal unsigned integer type% stands for unsigned decimal.
Hexadecimal integer, %u for unsigned integer,% for exponential type and% for string type. You can control the width and number of decimal places of data by adding a number between% and format characters.
[test point 5]scanf function
The entry requires an address character &; . When multiple data are entered through the keyboard, separators are used between the data. Delimiters include spaces, tabs and carriage returns, but do not include commas] 6 How to exchange two variables?
To use intermediate variables, the statement is: t-x; x-y; x-t; .
Chapter III Selection Structure
[test site 1] relational operation
C language uses non-zero to represent logical truth and 0 to represent logical false. There are six relational operators, namely >, days, =, =, and the first four have higher priority than the last two. The relational expression is 1 when it is true and 0 when it is false. Note that asbec is not allowed, and (ASB)8 &;; (bec) to express.
[Test Site 2] Logical Operation
There are three logical operators * * *: logical AND(8 & amp; ), logic OR (1), logic NOT (! )。 Pay attention to short circuit phenomenon, such as atlbl, if expression.
If the value of al is not zero, the expression bl will no longer be executed.
[Test Site 3] If statement
Can appear alone or with els. If statements can be nested when ese is always associated with the nearest and no.
F- matching of else matching
[Test Site 4] Conditional Operation
Is the only three-eye operator with the format: expression 1? Expression 2: Expression 3. When the value of expression 1 is non-0, the value of the whole expression is the value of expression 2, and when the value of expression 1 is 0, the value of the whole expression is the value of expression 3.
[Test Site 5] Switch statement
See P33 for the format and implementation process. Pay attention to whether the break statement after each case is different. Also pay attention to the switch.
The expression in parentheses cannot be a real number, and the expression after case cannot have variables. Formula: the switch table is not established, and the case table remains unchanged.
Chapter IV Cyclic Structure
[Test center 1] Three circulation structures
These three loop structures are: while, dowhile, for. See page 3639.40 of the textbook for the format and execution order of the three structures. Note that the for loop must have two semicolons in parentheses: the loop must have an end condition, otherwise it will become an infinite loop: the last while0: of the do-while0 loop must be followed by a semicolon.
[Test Site 2] Interrupt and Continue
Break means ending the whole cycle, and continue means ending the current cycle ahead of schedule. Break statements can appear in loop structures and switch statements. Continue only appears in loop structures.
[Test Center 3] Circulating condoms
That is, there is a cycle in the cycle, and the calculation needs to be analyzed layer by layer. Generally, only two levels of nesting are investigated, and circular nesting usually deals with two-dimensional groups.
[Test Site 4] Review of Cycle Structure
The circular structure is the key point, and the written test score is generally around 13, which is also a necessary test point for computer examination and has strong application. ask
Students are required to focus on understanding and practicing more, and master the bit operation of character data in Chapter 5.
[test site 1] character constant
A character constant is enclosed in a pair of single quotation marks, and the sound weight of a character can only contain one character. Ab' is illegal. Spaces are usually represented by "mouth". Character constants can be represented by corresponding ASCI codes. Remember: the ASCII code of "0" is 48. A', ASC code is 65a', ASCII code is 97.
[Test Site 2] Escape Characters
A backslash in a pair of single quotes is followed by a specific character or an octal or hexadecimal number to form an escape character. For example,' n stands for line feed, and 10 1' or' 1' stands for the character' a' with ASCII code of 65.
[Test Site 3] Character data can be converted into integer data.
Such as:' 0'-0 '-0-48A '+32 =' a' chara-65;-65; printf(" % % " aa); The result is 65A.
[test site 4] bit operator
C language provides six bitwise operators: bitwise negation, bitwise left shift and bitwise right shift. , bitwise XOR, bitwise OR. In general, you need to convert to decimal first. The rule of XOR operation: 0 XOR 1 take 1 XOR 0 take 0 1 XOR 1 take 0 can be recorded as "both are 0, but different are 1".
[Test Site 5] Putchar and getchar functions
It can be used to output or input a single character. These two functions are library functions in stdioh file, which are prinf and scanf functions respectively.
Simplification of numbers.
Chapter VI Functions
Definition of [test center 1] function
Abundance is a program block with certain functions. The head of the function is: function type function name (type 1 formal parameter 1 formal parameter 2).
2...)。 You cannot define a function in a function definition, that is, you cannot define a function. The function type defaults to int type. [test site]
[Test Site 2] Library function
When calling the C language standard library function, it contains a command, which starts with # and is followed by ""or a header file with suffix. H "closed. Lines starting with # are called compilation preprocessing command lines. Compiler preprocessing is not a C language statement, so it is not signed and does not take up running time.
[Test Center 3] The return value of the function
The function returns the value through the return statement, and the return value type is the same as the function type. The return statement is only executed once, and exits the rain number after the execution or the beautiful body is finished.
[Test Site 4] Function Statement
Functions should be defined before calling, or declared before calling, and then defined. A function declaration must have a function name, a function return value type and a function parameter type, but not necessarily a tangible parameter name.
[Test Site 5] Function Call
The program is executed from top to bottom. When it encounters a function name, it passes the value to the calling function. When the program gets the return value or the calling function ends, it is executed in sequence.
Parameter and value transfer of [Test Point 6] function
Formal parameters, referred to as formal parameters, are parameters in parentheses after the function name when defining a function. Real parameters, called real parameters for short, are the parameters in parentheses after the function name when calling the function. Real parameters and shape parameters occupy different storage units respectively. Real parameters pass numerical values to shape parameters in one direction. The difference between "passing value" and "passing address": If the value is passed, the change of formal parameters will not change the change of actual parameters. If the address is passed, the change of formal parameters may change the number of corresponding real parameters.
Recursive call of [Test Site 7] function
Functions directly or indirectly call recursive calls of their calling functions. Recursive calls must have a clear condition to end recursion. When doing recursive problems, you can write down the recursive steps step by step, and don't get confused.
[Test Site 8] Required Library Functions
Sgrt0 arithmetic square root function, fabs0 absolute value function, pow0 power function, sin0 sine function.
Chapter VII Pointer
[test site 1] pointer variable
[Test Center 2] Definition of pointer variable
Pointer variables are used to store addresses, while general variables store numerical values. A pointer variable can point to any data type, but no matter how many bytes the data it points to takes up, the pointer variable takes up four bytes. The format is: type name * pointer variable name. The two-dimensional pointer inttsp can be understood as the base type is (ints) type.
[Test Center 3] Pointer variable initialization
Pointer variables must be initialized before they are used, and they should be assigned a specific address, otherwise there will be side effects when they are referenced. If they don't point to any data, they will be given an "empty" NLI.
[Test Site 4] Reference of pointer variables
& is the address operator and * is the indirect access operator. They are two reciprocal operators. Add an odd number of indirect access operations before the pointer variable name, which is equivalent to the amount it points to.
[Test Site 5] Operation of the pointer
* The difference between *pll and (*p)++ pt+ is the address change, and () refers to the dataization of pointer change. Adding an integer to a pointer variable is not a simple mathematical addition, but a continuous movement of several addresses. When two pointers point to the same array, they can compare the sizes and subtract them.
Chapter 8 Array
Definition of [test site 1] array
An array is a set of data of the same type, called an array element. The format is: type name array name [constant expression]. The number of bytes occupied by an array is the product of the number of elements and the number of bytes occupied by the base type.
[Test Point 2] Array Initialization
The length of the first dimension may not be written, and other dimensions must be written. intII=( 1,2); Legal,int |[3]-234; Legal, int 12]=(2 34) illegal. The default value of the initialized element of the array is 0, and the value of the uninitialized element is random. Such as inta [5] = 012); In, the value of element 4 is 0: whereas in inta [5; The value of element a[4] is an uncertain random number.
Reference [Test Point 3] element
The subscripts of array elements start from 0 and end with the array length minus 1. so int[5]; The last element in the array is a[4]. In order to treat the array elements as a whole, we can treat a[4] as an integer variable.
[Test Center 4] Input and output of character strings
You can use scanf and printf functions, such as scanf ("%s ",str); You can also use two functions, gets and outs, to deal with strings. You can also assign values to character arrays one by one, but you must assign a' 10' at the end. Use the gets function to receive spaces, and use the puts function to output a line break at the end.
[Test Site 5] String function
There are four character application functions that need to be mastered: character string copying function strcpy () searching character length function strlen () character string linking function strcat () character string comparison function stramp (). To use these functions, you need to include the header file "stringh" in the preprocessing part, and the length of the string should be less than the length of the character array, for example: ciarsid10] = "hello"; The value of sizeof(str) is 10 (array length). The value of strlen(str) is 5 (string length). These functions are commonly used in exams, so you must use them skillfully.
Chapter 10 Structure and Usage of * * *
[Test site 1] Description of structure type A structure is a collection of several types of data, and the description format of structure type is as follows: structure type name type 1 member name 1 type 2 member name 2; Small, the whole part above is data type and integer nt in the same position. Typedef can be used to replace the structure type with a short identifier with only a few letters.
[Test Center 2] Definition of structural variables
A structural variable is a variable defined by the described structural type, which is different from the structural type. The number of bytes occupied by a structure variable is the sum of the bytes occupied by all its members. Such as struct stuchar name1:intage: ab; It means that two structural variables ab are defined, each of which occupies 4 bytes. Ab and variable ii are in the same position in int.
[Test Site 3] Structural Component Reference
There are three ways to reference members: (1 structural variable name member; (2) Pointer variable name Member name: (3) Member name. Dot () member operator, header (always
[Test Site 4] Linked List
A linked list is composed of nodes, and a node is a structural variable. Each node can be divided into two parts: data field and pointer field. The data field is used to store the data to be stored and the pointer field is used to point to the next node. Linked list is a difficult point in the exam. Both C language and public Basic Part will be tested, so we should grasp it.
[Test Site 5]*** verbs
* * * The use format of subject is similar to that of structure, and the keyword defined by subject is union * * * The number of bytes occupied by subject is the largest among all members.